We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Advanced
  4. Triplets

Triplets

Problem
Submissions
Leaderboard
Discussions
Editorial

There is an integer array which does not contain more than two elements of the same value. How many distinct ascending triples () are present? 

Input format
The first line contains an integer, , denoting the number of elements in the array. This is followed by a single line, containing space-separated integers. Please note that there are no leading spaces before the first number, and there are no trailing spaces after the last number.

Output format:
A single integer that denotes the number of distinct ascending triplets present in the array.

Constraints:

Every element of the array is present at most twice.
Every element of the array is a 32-bit non-negative integer.

Sample input:

6  
1 1 2 2 3 4  

Sample output:

4

Explanation
The distinct triplets are
(1,2,3)
(1,2,4)
(1,3,4)
(2,3,4)

The elements of the array might not be sorted. Make no assumptions of the same.

Author

HackerRank

Difficulty

Advanced

Max Score

90

Submitted By

5016

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website