PREP23 Editorial

Problem Explanation

We have to print the maximum element in all the subarrays of size x in an array A in the order as they occur in the array.

Approach

  • We use dequeue
  • We iterate over the array
    • while dequeue is not empty and the current element is greater than equal to the element in A as position pos where pos is the last element in the dequeue
      • we remove the last element in the dequeue
    • we push the current index in the dequeue
    • if the indexes processed are greater than equal to x
    • if the current index is not in the first window and the difference between the first index and the current index is equal to X then
      • the first element is popped.
    • we print the element in the array at the index at the front of the queue.