Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
Using the sliding window technique, what is the maximum sum of any 8 consecutive elements in [24, 30, 4, 27, 25, 2, 13, 22, 26, 1]?
- A. 154
- B. 148
- C. 149
- D. 125
Correct answer: C. 149
Slide a window of size 8, adding the new element and dropping the oldest one in O(1) per step; the best window sum is 149.
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
- A singly linked list has nodes at positions 0..6 holding 58 -> 20 -> 49 -> 17 -> 78 -> 37 -> 22, but the last node's next pointer points…
- Heap sort (build a max-heap, then repeatedly swap the root with the last unsorted element and sift down) is run on [1, 27, 40, 40, 63, 2…
- A monotonic decreasing stack of indices is used to compute the next-greater-element array for [41, 35, 17, 34, 4, 37, 29, 44] (push index…
- What is the space complexity of this recursive factorial function, as a function of n (ignoring the final integer result size)? c int…
- Evaluate the postfix expression: 6 3 + 7 + 9 +
- Evaluate the postfix expression: 1 1 - 5 - 5 -