PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Other

Implement a multi-button click detector

Last updated: Mar 29, 2026

Quick Overview

This question evaluates competency in real-time event stream processing, per-button state management, and timing-based classification of input events such as distinguishing single versus long presses.

  • hard
  • Other
  • Coding & Algorithms
  • Software Engineer

Implement a multi-button click detector

Company: Other

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

Implement a click detector for multiple physical buttons. You receive button state updates as a stream. Each update provides: - `button_id` (integer) - `state` where `1 = pressed`, `0 = released` - (initially) updates arrive every **10 ms** per button (you may assume updates are ordered in time). A “click” is a press followed by a release. Classify each completed click as: - **Single Click**: press duration **≤ 200 ms** - **Long Click**: press duration **≥ 500 ms** For each detected click, output something like: - `Button 1: Single Click` - `Button 2: Long Click` Requirements / edge cases: - Support **multiple buttons** concurrently. - Handle **back-to-back clicks** on the same button (press/release cycles repeated over time). - Handle **no click** (e.g., no transitions) without producing output. - Clarify/handle what to do for press durations in the **(200 ms, 500 ms)** gap. Follow-up: If state updates do **not** arrive every 10 ms (variable intervals), how would you modify the implementation? Assume you can obtain timestamps (e.g., via a system call like `now_ms()`) for each update.

Quick Answer: This question evaluates competency in real-time event stream processing, per-button state management, and timing-based classification of input events such as distinguishing single versus long presses.

Related Interview Questions

  • Compute total after discounting most expensive item - Other (medium)
  • Return the k-th row of Pascal-like triangle - Other (medium)
  • Implement multiplication without using the multiplication operator - Other (Medium)
  • Prove reservoir sampling correctness - Other (Medium)
  • Write mini-batch gradient descent - Other (Medium)
Other logo
Other
Feb 3, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0

Implement a click detector for multiple physical buttons.

You receive button state updates as a stream. Each update provides:

  • button_id (integer)
  • state where 1 = pressed , 0 = released
  • (initially) updates arrive every 10 ms per button (you may assume updates are ordered in time).

A “click” is a press followed by a release. Classify each completed click as:

  • Single Click : press duration ≤ 200 ms
  • Long Click : press duration ≥ 500 ms

For each detected click, output something like:

  • Button 1: Single Click
  • Button 2: Long Click

Requirements / edge cases:

  • Support multiple buttons concurrently.
  • Handle back-to-back clicks on the same button (press/release cycles repeated over time).
  • Handle no click (e.g., no transitions) without producing output.
  • Clarify/handle what to do for press durations in the (200 ms, 500 ms) gap.

Follow-up: If state updates do not arrive every 10 ms (variable intervals), how would you modify the implementation? Assume you can obtain timestamps (e.g., via a system call like now_ms()) for each update.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Other•More Software Engineer•Other Software Engineer•Other 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.