Count Steps From Smartwatch Accelerometer Magnitude Peaks
Last updated: November 29, 2026
Quick Overview
Given a stream of 3-axis accelerometer samples from a watch, a magnitude threshold and a minimum gap in samples, count steps as local magnitude peaks above the threshold that are at least the gap apart from the previous counted peak.
Samsung
November 29, 20260
0
0 solved
Given a stream of 3-axis accelerometer samples from a watch, a magnitude threshold and a minimum gap in samples, count steps as local magnitude peaks above the threshold that are at least the gap apart from the previous counted peak.
Galaxy Watch and Samsung Health count steps on a low-power sensor core, so a simple peak detector is a good warm-up for wearables and firmware candidates. The interviewer is checking clean single-pass logic and whether you think about noise, plateaus and debouncing.
What the Interviewer Expects
- Computes vector magnitude so orientation does not matter
- Single pass, O(1) extra state beyond the magnitudes
- Defines peak precisely, including a rule for flat tops
- Applies a refractory gap to avoid double counting
- Mentions filtering and gravity removal as real-world improvements
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you make this streaming with O(1) memory?
- How would you choose the threshold adaptively for different users and walking speeds?
- How would you reject false steps when the user is riding in a car?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of (x, y, z) in m/s^2, threshold T, gap G (samples). A sample i counts if its magnitude exceeds T, it is a local maximum, and i minus the previous counted index is at least G....
High-Level Design
Compute magnitude per sample, then scan interior indices. For plateaus, use >= on the left and > on the right so exactly one sample of a flat top counts (the last one). Track last index of the c...