Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many windows of length 3 in [1, 2, 3, 1, 2, 2, 4, 1, 3, 4] contain three pairwise distinct values?
- A. 10
- B. 6
- C. 8
- D. 3
Correct answer: B. 6
There are 10 − 3 + 1 = 8 windows; slide a frequency map and test whether it holds 3 keys. Only [1,2,2] and [2,2,4] repeat a value, so 6 qualify. Counting every window gives 8, 10 is the array length, and 3 counts only the non-overlapping blocks.
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
- In the string "bbaacbbaaac", what is the length of the shortest contiguous substring that contains at least three letters 'a'?
- Piles of bananas are [3, 6, 7, 11] and you must finish all piles within 8 hours, eating at speed k bananas per hour (taking ceil(pile / k)…
- The array [7, 2, 5, 10, 8] is split into exactly 2 non-empty contiguous parts so that the largest part sum is as small as possible. What…
- How many non-empty contiguous subarrays of [4, 5, 0, -2, -3, 1] have a sum divisible by 5 (including negative sums, which are divisible…
- An array of 6 zeros (indices 0 to 5) receives three range-add operations, each adding v to every index from l to r inclusive: (1,3,+2)…
- The stock span of day i is the number of consecutive days up to and including i with price at most price[i]. What is the sum of the spans…