I feel this is a better way of implementing the refresh method: private void refresh(long currTimeInSec) { long cutoffTime = currTimeInSec - windowInSecs; while(!window.isEmpty() && window.peek() < cutoffTime) window.poll(); }
Thanks for your video. One question. Do we actually need to calculate ''çalculatedTime' multiple time in while loop? Because the queue works on FIFO basis and if the top of the queue is expired for that sliding window isn't it the remaining entries of the queue also will be expired? Your thoughts please..
as you already mentioned the queue works as FIFO so the top of the queue is the oldest so time diff also will be greater and could exceed the defined limit, but the same could not be the case for the latest ones
Basic idea will be like ola or uber, on top of this architecture you can add more functionality. Do check out this video and let me know if you are expecting something more ruclips.net/video/AbvBcmABjcI/видео.html
I feel this is a better way of implementing the refresh method:
private void refresh(long currTimeInSec) {
long cutoffTime = currTimeInSec - windowInSecs;
while(!window.isEmpty() && window.peek() < cutoffTime)
window.poll();
}
Thanks for your video.
One question. Do we actually need to calculate ''çalculatedTime' multiple time in while loop? Because the queue works on FIFO basis and if the top of the queue is expired for that sliding window isn't it the remaining entries of the queue also will be expired? Your thoughts please..
as you already mentioned the queue works as FIFO so the top of the queue is the oldest so time diff also will be greater and could exceed the defined limit, but the same could not be the case for the latest ones
Can you also make a video on Sliding window with counters. Or atleast guide what will change in this code? Awesome video between.
To implement sliding with counter you can use map instead of queue. That would solve the requirement.
Employee class is not present while building the code
Nice video
Hope it was helpful. Do like and subscribe and share with others 🙂
Bro BlaBlaCar system design ... Plz
Basic idea will be like ola or uber, on top of this architecture you can add more functionality. Do check out this video and let me know if you are expecting something more
ruclips.net/video/AbvBcmABjcI/видео.html