Using Tuples in python
In this problem, you will be given an array A of integers of fixed size N and an integer K and you have to find the number of tuples (i, j) such that the following properties are satisfied,
● A[i]*A[i+1]*A[i+2]...A[j-1]*A[j] < K
● -1 < i < N
● i < j + 1
Note that the array is 0-indexed.
Input Format
The first line will contain integers N and K separated by a single space. The second line will contain N space separated integers.
Output Format
A single line containing the number of tuples.
Constraints
● 0 < N < 5000
● -1000 < A[i] < 1000
● 0 < K < 109
PYTHON CODE:
n,k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
ans = 0
for i in range(0,n):
curr_product = 1
for j in range(i,n):
curr_product = curr_product*arr[j]
if curr_product<k:
ans += 1
print(ans)
NOTE: Please refer the following screenshot in case of indentation error.
CODE SCREENSHOT:
Get Answers For Free
Most questions answered within 1 hours.