Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5594
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3412
Triplets with sum with given range
Medium Accuracy: 44.66% Submissions: 1128 Points: 4

Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R].

Example 1:

Input:
N = 4
Arr = {8 , 3, 5, 2}
L = 7, R = 11
Output: 1
Explaination: There is only one triplet {2, 3, 5}
having sum 10 in range [7, 11].

Example 2:

Input:
N = 5
Arr = {5, 1, 4, 3, 2}
L = 2, R = 7
Output: 2
Explaination: There two triplets having
sum in range [2, 7] are {1,4,2} and {1,3,2}.

You don't need to read input or print anything. Your task is to complete the function countTriplets() which takes the array Arr[] and its size N and L and as input parameters and returns the count.

Expected Time Complexity: O(N2)
Expected Auxiliary Space: O(1)

Constraints:
1 ≤ N ≤ 103
1 ≤ Arr[i] ≤ 103
1 ≤ L ≤ R ≤ 109