Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Selecting Three People

Moderate
0/80
Average time to solve is 25m
0 upvote
Asked in company
D.E.Shaw

Problem statement

There are ‘N’ people standing in a row having heights that may or may not be the same. You have to find the number of ways to select three people with heights in strictly increasing order along with their positions. Formally, the height of first people < the height of second people < the height of third people and the position of first people < the position of second people < the position of third people.

Detailed explanation ( Input/output format, Notes, Images )
Constraints :
1 <= T <= 10
3 <= N <= 100
1 <= ARR[i] <= 10 ^ 5

Where 'ARR[i]' denotes the height of the i-th people in the row.

Time limit: 1 sec
Sample Input 1 :
2
4
1 2 3 4
5
3 3 4 5 6
Sample Output 1 :
4
7
Explanation of sample input 1 :
In the first test case, the selection can be made as [1, 2, 3], [1, 2, 4], [1, 3, 4], and [2, 3, 4].

In the second test case, the selection can be made as [3, 4, 5], [3, 4, 6], [3, 5, 6], [3, 4, 5], [3, 4, 6], [3, 5, 6], and [4, 5, 6].
Sample Input 2 :
3
3
3 2 1
3
3 3 3
3
1 2 3
Sample Output 2 :
0
0
1
Explanation of sample input 2 :
In the first test case, there is no way to select three people with the required conditions.

In the second test case, there is no way to select three people with the required conditions.

In the third test case, the selection can be made as [1, 2, 3].
Full screen
Console