Error
|
|
---|---|
@Ibrahim Nash | 6381 |
@blackshadows | 6329 |
@mb1973 | 5388 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3357 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@1905439 | 553 |
@terabaap123 | 508 |
@smitadiwedi1991 | 279 |
@DevanandJayakumar | 250 |
@atishagusain | 244 |
@gupta_10 | 226 |
@shubhamkhullar7 | 224 |
@nipun edara | 224 |
@balunagar | 204 |
@sharmachandan487 | 204 |
@arshjit_singh7 | 190 |
Complete Leaderboard |
Given an array of size n, a triplet (a[i], a[j], a[k]) is called a Magic Triplet if a[i] < a[j] < a[k] and i < j < k. Count the number of magic triplets in a given array.
Example 1:
Input: arr = [3, 2, 1]
Output: 0
Explanation: There is no magic triplet.
Example 2:
Input: arr = [1, 2, 3, 4]
Output: 4
Explanation: Fours magic triplets are
(1, 2, 3), (1, 2, 4), (1, 3, 4) and
(2, 3, 4).
Your Task:
You don't need to read or print anything. Your task is to complete the function countTriplets() which takes the array nums[] as input parameter and returns the number of magic triplets in the array.
Expected Time Complexity: O(N2)
Expected Space Complexity: O(N)
Constraints:
1 <= length of array <= 1000
1 <= arr[i] <= 100000
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes