GOLDMANSACHS Coding Question – Solved
There are 'N' coders standing in a line, where i denotes the ith position of a coder with a rating of Ri. All ratings are distinct.
You have to form a team of 3 from amongst them with the condition:
- Any three coders with positions (i, j, k) and ratings (Ri, Rj, Rk) can form a team when ("Ri < Rj < Rk" or "Ri > Rj > Rk") and (1 <= i < j < k <= N).
You have to find out how many such teams exist (1 coder can be part of multiple teams).
Input:
N - 5
Ratings - 5 23 14
Output:
3
(5,2,1), (5,3,1), (2,3,4)