Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
For windows of size 3 over [3, 1, 4, 2, 5, 1, 6, 0], how many windows have their maximum at the last position of the window (ties count as yes)?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
Check each window's last element against the deque's front; ties count because the maximum equals the last element. Inspecting only strict maxima undercounts.
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
- Four unit-time jobs given as (deadline, profit) are (4, 20), (1, 10), (1, 40), (1, 30). Each job must finish by its deadline and only one…
- What is the length of the shortest contiguous subarray which, if sorted in place, makes the whole array [2, 6, 4, 8, 10, 9, 15] sorted?
- What is the number of trailing zeros in the decimal representation of the product 10 25 4 15 50?
- How many distinct sums appear over all non-empty contiguous subarrays of [2, 1, 3, 1]?
- Ropes of lengths 4, 3, 2 and 6 must be joined pairwise into one rope; joining costs the sum of the two lengths and you may join any two…
- How many distinct palindromic strings of length 3 occur as subsequences of "abcba"?