Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
Over all windows of size 3 in [4, 8, 2, 7, 5, 9], what is the smallest value of (window max minus window min)?
- A. 5
- B. 3
- C. 4
- D. 7
Correct answer: C. 4
Two monotonic deques give each window's maximum and minimum in amortised O(1). The window [7, 5, 9] has spread 4, which is the smallest here.
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
- How many index pairs i < j of length-2 substrings of "ababa" are equal strings?
- What is the smallest positive integer x such that floor(x/2) + floor(x/3) is at least 10?
- In [3, 8, 1, 8, 5], you move the rightmost occurrence of the maximum to the last position using adjacent swaps. How many adjacent swaps…
- How many unordered pairs of distinct words in ["abc", "aba", "cdc", "xyz", "axa", "cd"] share both the same first letter and the same last…
- How many index pairs i < j of [1, 2, 5, 7, 10] have absolute difference at least 3?
- Numbers 1, 2, 3, 4 are pushed in this order onto a stack. Can the pop sequence 3, 4, 2, 1 be produced?