0

A Queue is being used as a sliding range with 250 integers of 2500 integers in a Linked List. In each iteration, the Queue is moved one position forward on the Linked List by Dequeuing and then Enqueing the next integer in the Linked List. Every time the Queue slides one position, the Max integer of the Queue is found by iterating through nodes in the Queue.

Can this process be sped up by replacing the iteration to update the max with calculating the newMax from the variables previousMax, dequeued, enqueued and sumOfPreviousQueue? This seems like it should be possible with arithmetic, but I can't figure it out.

Kyle Gee
  • 35
  • 6
  • "If your question includes code" - What would code add to the problem? Is it not explained clearly? – Kyle Gee Feb 02 '20 at 04:55
  • 2
    @KyleGee: it's called a "sliding window maximum", or "maximum of subarrays", you can find [examples online](https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/). – Groo Feb 02 '20 at 05:04

0 Answers0