Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.
Input :
arr[] = {-2, 0, 1, 3}
target = 2.
Output :
2
Explanation : Below are triplets with sum less than 2
(-2, 0, 1) and (-2, 0, 3)
def countrip(arr, n, sum): temp=0 for i in range( 0 ,n-2): for j in range( i+1 ,n-1): for k in range( j+1, n): if (arr[i] + arr[j] + arr[k] < sum): temp+=1 return temp arr= list(map(int,input('Arr : ').split(' '))) n = len(arr) sum = int(input('Target : ')) print(countrip(arr, n, sum))
Input_1:
Arr : -2 0 1 3
Target : 2
Output:
2
Input_2:
Arr : 5 1 3 4 7
Target : 4
Output:
0
Input_3:
Arr : 5 1 3 4 7
Target : 12
Output:
4
Input_4:
Arr : 1 3 4
Target : 5
Output:
0
Input_5:
Arr : 1 4 0 3
Target : 5
Output:
1
Illustration
More Q
- Determine if a person could attend all meetings in given interval times.
- Find the volume of a volley ball
- Find the maximum score obtained at the end of colour chess grid game.
- Find the number of pairs if positive integers with condition is even.
- Return the largest subset such that every pair meets the given condition.
- Find the number of index triplets that satisfy given condition.
- Handling multiple queries using array – sum, update, range.
- Find all the sequences that occur more than once in DNA molecule.
- Find the biggest number.
- Sum of cube of each number is again equal to the number then it is an Armstrong number.
- Hello World.
- Calculate the Cube Root.
- Find the count of consecutive 1’s present in array.
- Return an array with athletes relative ranks according to the score.
- Return a string of its base 7 representation.
- Return kth largest element in sorted order.
- Find all repeated elements in the array.
- Find atleast one duplicate number in the array.
- Find the maximum result of = a XOR b.