Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many distinct sums arise from the length-3 windows of [1, 1, 2, 2, 3, 3, 1]?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
The five windows have sums 4, 5, 7, 8, 7; the repeated 7 is counted once, giving 4 distinct values.
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
- Among index pairs i < j of [-8, -3, -1, 2, 5, 9], how many pairs have the minimum possible absolute value of their sum?
- For [4, 1, 3, 7, 2], what is the maximum over index pairs i < j of min(a[i], a[j]) times (j - i)?
- How many non-empty substrings of "aabcab" are already in non-decreasing (sorted) order?
- What is the sum of the maxima of every window of size 2 in [9, 4, 7, 1, 8]?
- How many contiguous subarrays of [1, 2, 3, 4, 6, 1] have a product exactly 12?
- Starting at index 0 of [1, 2, 1, 1, 1], each a[i] is the maximum forward jump. What is the minimum number of jumps needed to reach the…