Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B
Among the windows of exactly 3 consecutive elements of [4, 2, 4, 1, 3, 5, 2, 6] whose 3 values are all different, what is the largest window sum?
- A. 14
- B. 8
- C. 18
- D. 13
Correct answer: D. 13
Check distinctness with a count per window (or a sliding window with counts), then take the best sum among the valid windows. Ignoring the distinctness test picks windows such as 4, 2, 4 that a reader might mistake for valid.
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
- Consider only the elements at even 0-based indices of [5, 2, 8, 1, 7, 3, 9, 4] (that is, 5, 8, 7, 9). How many inversions (pairs i < j of…
- What is the length of the longest contiguous subarray of [2, 1, 5, 1, 3, 2, 4, 1] whose sum is at most 9? All values are non-negative.
- Each operation decreases one element of [5, 3, 4, 2, 6] by exactly 1. What is the minimum number of operations needed to make the array…
- A staircase has 10 steps. You climb 1, 2 or 3 steps at a time but may never land on step 4 or step 7. Starting at step 0, how many…
- How many sequences of length 4 with entries from {1, 2, 3} are non-decreasing (each entry is at least the one before it)?
- A frog at position 0 wants to land exactly on position 17. Each jump has length 3, 5 or 7. What is the minimum number of jumps needed, or…