Citadel Online Assessment | Triplets | Citadel OA 2022

Given an array of n distinct integers, and an integer threshold, how many (a,b,c) index triplets exist that satisfy both of the following conditions?

  • arr[a] < arr[b] < arr[c]
  • arr[a] + arr[b] + arr[c] <= t

Relevant Citadel OA Problems:

Parameter

  • arr: an array of integers
  • t: an integer threshold

Result

  • An integer that denotes the number of (a,b,c) triplets that satisfy the given conditions.

Example

Input: arr = [1, 2, 3, 4, 5], t = 8

The following 4 triplets satisfy the constraints: (1,2,3), (1,2,4), (1,2,5), (1,3,4).

Output: 4

Try it yourself

Solution

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro