The Debounce interview question is a classic front-end and system design task. You need to implement a function that accepts a callback and a delay time t. The debounced function should ensure that the callback is only executed after t milliseconds have passed since the last time the debounced function was called. This is used to limit the frequency of expensive operations like API calls during a window resize or keypress event. This Debounce coding problem is a test of your understanding of timers and closures.
Tech companies like Meta and Google ask this because debouncing is a critical performance optimization in real-world web applications. It tests your knowledge of Asynchronous Programming, Closures, and the this context in JavaScript. It evaluates whether you can manage state (the timer ID) across multiple function calls.
This problem relies on the Timer and Closure pattern.
Imagine a search bar that calls an API on every keystroke.
Understand the difference between Debounce (wait for a pause) and Throttle (execute at most once every X ms). Interviewers often ask you to compare the two or implement both.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| 4Sum II | Medium | Solve | |
| Detect Squares | Medium | Solve | |
| Find the Number of Ways to Place People I | Medium | Solve | |
| Find the Prefix Common Array of Two Arrays | Medium | Solve | |
| Longest Arithmetic Subsequence of Given Difference | Medium | Solve |