Data Structures & AlgorithmsModerateProduct-company MCQ pattern
A fixed-size sliding window of length 3 moves over [2, 1, 5, 1, 3, 2, 9, 1]. What is the largest window sum?
- A. 15
- B. 9
- C. 12
- D. 14
Correct answer: D. 14
Window sums are 8, 7, 9, 6, 14, 12 (each new sum = previous + entering element − leaving element), so the maximum is 3 + 2 + 9 = 14. 12 is the last window, 2 + 9 + 1.
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 element shifts does insertion sort perform to sort [4, 3, 2, 10, 12, 1, 5, 6] in ascending order?
- Quick sort with the Lomuto partition (pivot = last element) is run on an already sorted array of 10 distinct elements. How many…
- Binary search (one three-way comparison per probe) is done on a sorted array of 1000 elements. What is the maximum number of probes needed?
- This code tries to reverse the singly linked list 1 → 2 → 3 → 4, but its last line has been changed from cur = nxt. What does the list…
- A linked list has 3 nodes before the loop starts and a loop of 5 nodes. Floyd's slow pointer moves 1 step and fast pointer 2 steps per…
- ^ is exponentiation (highest precedence, right-associative). What is the postfix form of A + B C ^ D ^ E − F?