Data Structures & AlgorithmsVery hardFlipkart/Uber OA · placement
How many contiguous subarrays of [5, 3, 4, 5, 1, 1, 6, 5] have a sum between 6 and 10 inclusive? (All values positive: count atMost(10) − atMost(5) with sliding windows.)
- A. 17
- B. 7
- C. 10
- D. 9
Correct answer: D. 9
atMost(10) = 17 and atMost(5) = 8, so the count is 9. Subtracting atMost(6) instead of atMost(5) wrongly drops subarrays whose sum is exactly 6.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Keys 80, 42, 55, 92, 96, 24, 95, 69 are inserted in this order into an empty hash table of size 11 with h(k) = k mod 11 and linear…
- Two pointers start at both ends of the sorted array [2, 5, 10, 11, 12, 14, 16, 18, 21, 29]. How many pairs (i < j) have a[i] + a[j] ≤ 28?…
- Selection sort (ascending; in pass i find the minimum of the unsorted part and swap it into position i only if it is not already there) is…
- Rotate a linked list to the RIGHT by k places (k may exceed the length). What is printed? python def rotate(h, k): n, t = 1, h while t.nx…
- Exponential search: double the bound i (1, 2, 4, …) until a[i] ≥ key or i passes the end, then binary-search the last range. How many…
- For an n × n matrix whose rows and columns are both sorted ascending, what is the time of the staircase search for a key?