AI Interviews · Question

Write pseudocode for a sensor or motion-data algorithm, then use Claude to implement it, show you understand the generated code right away, and write tests for it.

AI-assisted coding question reported at Apple (2026). Sources, confidence and an answer card.

Researched · updated

r2a-016 Both tracks AI-assisted coding rounds AI-assisted coding Low confidence
On this page

What they’re really asking

If you only remember one thing, say this in the first minute: “I’ll write pseudocode where every step names a parameter I can test: a window size, a threshold, a minimum gap. That pseudocode is the contract. Then I’ll have Claude implement it, read the result line by line and explain it back to you. Finally I’ll test it with synthetic signals whose right answer I know in advance, so the tests check the spec, not whatever the generated code happens to do.”

The rest of this page explains each part of that answer.

The order is the point: spec first, generation second, understanding third.

In a normal coding round, your code is your understanding; if it works, you knew how. Here a model writes the code. Claude, like other assistants, is backed by a large language model (LLM): a program trained on huge amounts of text and code that writes a plausible reply to what you type. Generated code can drift from what you asked for in small ways, such as filtering after the threshold instead of before. If you test it by running it and writing down what it returns, your tests bless the drift. So you need tests that come from your pseudocode, with answers you knew before the code existed.

The report, seen only through search snippets of an Interview Query Apple AI Engineer guide, describes writing pseudocode for a sensor or motion-data algorithm, then using Claude to implement it, showing you understand the generated code right away, and writing tests for it (Interview Querysnippet only). Treat the details as low confidence. The skill is clear anyway.

Clarify first

  • What the algorithm must detect or compute. Step count, a fall, orientation, a smoothed signal?
  • Input. Sample rate, axes (accelerometer x, y, z; gyroscope?), units, and whether timestamps are regular.
  • Output. Per sample, per window, or events with timestamps?
  • Noise and edge cases. Dropped samples, sensor saturation (the reading hits its maximum and flattens), the device at rest.
  • Constraints. On-device memory and latency; streaming (one sample at a time) or batch.

Answer

Words you need first

  • Accelerometer: a sensor that reports acceleration along three axes, x, y and z, many times a second. The sample rate is how many readings per second.
  • Low-pass filter: smoothing that keeps slow changes and removes fast jitter. A moving average over the last few samples is the simplest one.
  • Peak: a point where the smoothed signal rises above a threshold and then falls again. In walking, roughly one peak per step.
  • Refractory period: a minimum time after one counted peak during which another peak is ignored, so one jittery step isn’t counted twice.

The pipeline, as pseudocode you can test

Take step counting from an accelerometer as the worked example. This is an assumption; the report doesn’t name the algorithm.

 samples (x, y, z) at a fixed rate
    │
    ▼
 1. magnitude = sqrt(x² + y² + z²)              ← one number per sample, whatever way the phone faces
    │
    ▼
 2. smooth = moving average over WINDOW samples  ← removes jitter
    │
    ▼
 3. peak if smooth crosses above THRESHOLD       ← candidate step
    │
    ▼
 4. ignore a peak within MIN_GAP of the last one ← refractory period
    │
    ▼
 step count

Each line names a parameter (WINDOW, THRESHOLD, MIN_GAP) you can state and test. Say it like this: “Every step has one knob, and every knob gets a test.”

Let the model implement it, then explain it back

Prompt with the pseudocode and the parameters, and ask for a streaming function and nothing else. Then read it line by line and explain it to the interviewer:

  • Where does the window state live between samples?
  • How are the first samples handled, before the window fills? (This is the warm-up, and generated code often skips it or divides by the full window size too early.)
  • Is the threshold compared before or after filtering? The pseudocode says after.

Any line you can’t explain, ask about and check. “I don’t see why it resets the counter here; let me ask, then check against step 4.”

Tests from the spec, not from the code

Make synthetic signals whose right answer you know before running anything. With assumed parameters (50 samples a second, a 5-sample window, a 0.3-second minimum gap):

Test signalKnown answerWhat it proves
Constant magnitude (the device at rest)0 stepsGravity alone doesn’t count as walking.
A sine wave at 2 cycles a second for 10 seconds, peaks above the threshold20 stepsPeaks 0.5 s apart are all counted, since 0.5 s is more than the 0.3 s gap.
Two spikes 0.1 s apart1 stepThe refractory period works.
The 2-cycle sine with every tenth sample missingabout 20 stepsDropped samples don’t crash or double-count.
The first 4 samples only0 steps, no crashWarm-up before the window fills.

These tests check the pseudocode’s claims, so they catch a generated implementation that drifted from it. A test written by running the code and copying its output would pass whatever the code does.

The arithmetic behind the numbers (for a Staff-level follow-up)
  • Sine test: 2 cycles a second × 10 seconds = 20 peaks, one per cycle, each 1 ÷ 2 = 0.5 s apart.
  • Refractory check: 0.5 s between peaks is longer than the assumed 0.3 s minimum gap, so none are dropped. Two spikes 0.1 s apart are closer than 0.3 s, so the second is ignored.
  • Window length: 5 samples at an assumed 50 samples a second is 5 ÷ 50 = 0.1 s of smoothing, short next to the 0.5 s between steps, so it smooths jitter without merging steps.

Senior vs Staff

Pseudocode, generate, test

Senior

  • Writes parameterized pseudocode, explains every generated line, and tests with synthetic signals that have known answers.

Staff

  • Names how parameters would be tuned and validated on real recorded data, and what on-device limits change in the design.

Small-team version

This is the spec-driven workflow small teams use with coding agents (assistants that can edit files and run commands themselves):

  • Write a short spec with parameters and acceptance tests.
  • Let the agent implement it, then review against the spec, not against your impression of the code.
  • Keep the tests. They are what survives when the agent rewrites the code next month.

For any AI feature, the same idea becomes an eval set: a fixed list of inputs with known right answers, run on every change to the prompt or model, the way unit tests run on every code change. Writing a first few dozen cases is a small job, and it is the only reliable way to tell whether a change made the feature better or just different.

Pitfalls

  • Pseudocode too vague to test. “Detect steps” has no knob to check.
  • Testing the generated code’s behavior instead of the spec’s claims. Copying the output into the test blesses any drift.
  • Not handling the warm-up. The first few samples arrive before the filter window is full.
  • Explaining the code by paraphrasing its comments. Read the logic; comments can be wrong too.

Go deeper

  • Family walkthrough: plan before code, who writes the spec and who types.
  • For known-answer test sets applied to an AI feature: Build Your Own RAG System, which measures retrieval against labelled queries.

Family

AI-assisted coding round in a provided codebase

Meta-style rounds (and their Microsoft, OpenAI, Apple and Fireworks cousins): fix a bug, build a feature and make it faster in a repo you've never seen, with an AI assistant you direct, check and sometimes overrule.

Other questions in this family