PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Apple

Implement a debounce function

Last updated: May 3, 2026

Quick Overview

This question evaluates a candidate's ability to implement a debounce utility using runtime features such as closures, timers, and function-context preservation, testing competencies in function design, stateful behavior, and event-rate control within the Coding & Algorithms domain.

  • medium
  • Apple
  • Coding & Algorithms
  • Software Engineer

Implement a debounce function

Company: Apple

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem: Implement `debounce(fn, wait)` Implement a `debounce` utility function. ### Behavior Given a function `fn` and a delay `wait` (milliseconds), `debounce(fn, wait)` returns a new function `debounced` such that: - When `debounced(...args)` is called repeatedly, it postpones calling `fn` until **after** `wait` ms have elapsed since the **most recent** call. - When the timer finally expires, `fn` is invoked **once** with the **latest** arguments and the original `this` context. ### Requirements - Preserve `this` binding when invoking `fn`. - The returned function should be callable multiple times. ### Optional extensions (if time) - Support `debounced.cancel()` to cancel a pending invocation. - Support `debounced.flush()` to immediately run the pending invocation (if any).

Quick Answer: This question evaluates a candidate's ability to implement a debounce utility using runtime features such as closures, timers, and function-context preservation, testing competencies in function design, stateful behavior, and event-rate control within the Coding & Algorithms domain.

Related Interview Questions

  • Compute Earliest Bus Arrival - Apple (medium)
  • Find the Extra Edge - Apple (hard)
  • Rotate a Matrix In Place - Apple (medium)
  • Encode and Rebuild a Binary Tree - Apple (hard)
  • Wrap Matching Substrings in Bold Tags - Apple (medium)
Apple logo
Apple
Feb 12, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
11
0
Loading...

Problem: Implement debounce(fn, wait)

Implement a debounce utility function.

Behavior

Given a function fn and a delay wait (milliseconds), debounce(fn, wait) returns a new function debounced such that:

  • When debounced(...args) is called repeatedly, it postpones calling fn until after wait ms have elapsed since the most recent call.
  • When the timer finally expires, fn is invoked once with the latest arguments and the original this context.

Requirements

  • Preserve this binding when invoking fn .
  • The returned function should be callable multiple times.

Optional extensions (if time)

  • Support debounced.cancel() to cancel a pending invocation.
  • Support debounced.flush() to immediately run the pending invocation (if any).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Apple•More Software Engineer•Apple Software Engineer•Apple Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.