That is why Sliding Window works:
- expand while the condition remains valid
- shrink when the condition becomes invalid
And because every element:
โข enters once
โข leaves once
the complexity becomes:
O(n)
That is the real intuition behind Sliding Window.
Understand / Revise the Sliding Window pattern in one post ๐
Sliding Window exists because brute force wastes work (this becomes clearer with the example below).
In many array/string problems, we repeatedly calculate information for contiguous ranges (subarrays/substrings).
Example:
[4,2,1] = 7 โ valid for condition (sum โค k), where k = 8
Expand right:
[4,2,1,7] = 14 โ invalid
Now we shrink from the left until validity is restored:
Remove 4 โ
[2,1,7] = 10 โ
Remove 2 โ
[1,7] = 8 โ
@Rohan2388@yajnshri How do you know that this particular person has been doing it? What if the one receiving this punishment might not even be the rickshaw driver who is doing all of this stuff. While there should be strict actions against those who create trouble, it shouldn't be this action though
@BenjDicken Hey Ben, With an experience of 2 years with reactJS, NextJS, NodeJS, expressJS, mongoDB and postgresQL (neonDB), building AI agent creation and management platform and SaaS approved over Shopify, Zapier and Meta platforms. Where do you think I could fit in?
Hey everyone, new on X. ๐
I build things from frontend to backend.
Available. Ready to contribute. Open to opportunities.
If you're building something and need a full stack dev, DM me. Let's talk. ๐
#application#developer#programmer#webdev
(4/4) The Solution: Debouncing
Fire only when the user pauses before doing anything. The moment you do something new (like typing a new character in search), the countdown starts over.
Sending only minimal requests/calls and avoiding it each instance of the tied event.
#code
debouncing in javascript is just teaching your code some patience
not every keystroke deserves a reaction. wait for the pause. then move.
honestly a life lesson too ๐๏ธ.
But what is debouncing in JS? A thread to explain (1/4)
#javascript#debounce
(3/4) the browser and server get hammered with redundant work
This same problem appears anywhere a function is tied to a high frequency event like scroll, mousemove, keystrokes, etc.