Data Structures & AlgorithmsHardTCS Digital · Infosys SP
What is the length of the shortest contiguous subarray of [1, 3, 5, 6, 3, 3, 7, 9, 4, 9] whose sum is at least 20? (All values are positive, so a shrinking sliding window works.)
- A. 5
- B. 3
- C. 4
- D. 2
Correct answer: B. 3
Expand right until the sum reaches 20, then shrink from the left while it stays ≥ 20, recording the length each time. The minimum length is 3.
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
- Count zero-sum contiguous subarrays with a prefix-sum frequency map. What is printed? python from collections import defaultdict a = [1…
- Bubble sort (ascending; each pass compares adjacent pairs left to right and swaps if out of order) is applied to [5, 42, 29, 4, 41, 8, 53…
- Stock prices over 8 days are [27, 32, 42, 42, 35, 66, 59, 31]. The span of day i is the number of consecutive days ending at day i…
- Assertion (A): Binary search runs in O(log n) time on a sorted singly linked list. Reason (R): Binary search halves the search range in…
- Two strings are isomorphic if characters can be replaced one-to-one to turn one into the other. Version A checks both directions; version…
- A monotonic deque reports the maximum of every window of size 3 in [0, 13, 9, 1, 2, 18, −1, −3, 17]. What is the SUM of all reported…