Question

Using Tuples in python In this problem, you will be given an array A of integers...

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

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
We are given an array A of size n containing n positive and negative integers (the...
We are given an array A of size n containing n positive and negative integers (the array is indexed starting from 0). Our goal is to find two indices i and j such that 0 ≤ i ≤ j ≤ n and Pk=j k=i A[k] is maximized. Input sequence: [2, -4, 1, 9, -6, 7, -3] Output: [1, 9, -6, 7] or i = 2 and j = 5 Input sequence: [1, 2, 3, 4, 5, 6, -3] Output: [1,...
Fix positive integers n and k. Find the number of k-tuples (S1, S2, . . ....
Fix positive integers n and k. Find the number of k-tuples (S1, S2, . . . , Sk) of subsets Si of [n] = {1, 2, . . . , n} subject to each of the following conditions separately, that is, the three parts are independent problems. (a) S1 ⊆ S2 ⊆ · · · ⊆ Sk. (b) The Si are pairwise disjoint (i.e. Si ∩ Sj = ∅ for i 6= j). (c) S1 ∩ S2 ∩ · ·...
In python Please The general elections are over, now is the time to count the votes...
In python Please The general elections are over, now is the time to count the votes and find out who will take the reins of this country. There are c (2 <= c <= 6) candidates and m (1 <= m <= 74) voting regions. Given the number of votes for each candidate in each municipality, determine which candidate is the winner (the one with the most votes). Input Format The first line of input contains an integer T (1...
# Problem Description Given a directed graph G = (V,E) with edge length l(e) > 0...
# Problem Description Given a directed graph G = (V,E) with edge length l(e) > 0 for any e in E, and a source vertex s. Use Dijkstra’s algorithm to calculate distance(s,v) for all of the vertices v in V. (You can implement your own priority queue or use the build-in function for C++/Python) # Input The graph has `n` vertices and `m` edges. There are m + 1 lines, the first line gives three numbers `n`,`m` and `s`(1 <=...
Given an unsorted integer array A of size n, develop a python version pseudocode with time...
Given an unsorted integer array A of size n, develop a python version pseudocode with time complexity as low as possible to find two indexes i and j such that A[i] + A[j] = 100. Indexes i and j may or may not be the same value.
Let B[1...n] be an array of integers. To express that no integer occurs twice in the...
Let B[1...n] be an array of integers. To express that no integer occurs twice in the B We may write? (check all the answers that apply) a) forall i 1..n forall j in 1...n B[i] != B[j] b)for all i in 1...n forall j in 1...n, i != j => B[i] !=B[j] c)forll i in 1...n forall j in 1...n i != j and B[i] != B[j] d)forall i in 1...n forall j in 1...n B[i] =B[j] => i=j e)forall...
1. You are given an array of integers, where different integers may have different number of...
1. You are given an array of integers, where different integers may have different number of digits, but the total number of digits over all the integers in the array is n. Show how to sort the array in O(n) time. 2. You are given an array of strings, where different strings may have different numbers of characters, but the total number of characters over all the strings is n. Show how to sort the strings in O(n) time. (Note...
Recall the 2-sum problem which took an array of N integers and determined the number of...
Recall the 2-sum problem which took an array of N integers and determined the number of pairs that summed to 0. Now consider a 2-sum BST problem. Let B be a binary search tree with N integers as unique keys. Using only data structures and algorithms that have been discussed in this class, describe an algorithm that will return the number of pairs in B that add to 0. Analyze the space and runtime of your algorithm.
DESCRIPTION: You will be given a 2D array, called matrix, of Strings. The array has an...
DESCRIPTION: You will be given a 2D array, called matrix, of Strings. The array has an unknown number of cells filled with data. Your goal is to iterate through the 2D array and keep a count of how many cells are full. You will be given the dimensions of the array. INPUT: All input has been handled for you: Two integers denoting the dimensions of the array. These are the integer variables rows and cols. A partially filled 2-D array....
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n,...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n, a positive integer, it returns a list of n tuples corresponding to the numbers 1 through n (both inclusive): the tuple for the number k consists of k as the first component, and exactly one of the following strings as the second: • the string 'two!' if k is divisible by 2 • the string 'three!' if k is divisible by 3 • the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT