Skip to content
Tech Interview Prep

Real Interview Questions for the Software Engineer at Apple

New

Practice MCQs

Answers count toward the Software Engineer and overall leaderboards; your latest answer to each question is the one that counts.

23 questions · Flow follows Relevance until this set has a learning order.

MCQ-1A capacity-3 LRU cache keeps a `HashMap<String, Node>` and a doubly linked list with `head`/`tail` sentinels. `get` on a hit unlinks the node and re-inserts it after `head`; `put` on an existing key overwrites `node.value` only; `put` on a new key inserts after `head` and, if size exceeds 3, unlinks `tail.prev` and removes its key from the map. After `put(a,1)`, `put(b,2)`, `put(c,3)`, `get(a)`, `put(b,20)`, `put(d,4)`, which key is evicted and what is the list order front to back?
MCQ-2A `char[]` of length 16 holds `a`, then twelve `b`s, then three `c`s. A two-pointer routine compresses it in place: for each run it writes the run's character at `write`, then, when the run is longer than one, the run's decimal count digit by digit, and returns the new length. What do the first six cells hold, and what does the routine return?
MCQ-3An E2EE messenger keeps each account's device list as one JSON document, last-write-wins on a server-assigned `seq`; records are `{device_id, key_version}`. D1 rotates v5→v6 at t=100: seq 41, `{D1:6, D2:1, D3:4}`. D2, whose cache still has D1 at v5, adds D4 at t=101: seq 42, `{D1:5, D2:1, D3:4, D4:1}`. The server keeps seq 42, and D1 deleted its v5 private key. D3 has been offline throughout; its own key is still v4. What does D3 hold after fetching, and what goes wrong?
MCQ-4A photo service keeps 2 billion photos, 4 MB originals (8 PB) and 200 KB thumbnails (400 TB), in one us-east object store, metadata in us-east Postgres. APAC p99 is 900 ms for thumbnails and 3 s direct for originals (1.6 s via CDN); 90% of views hit 5% of photos, each edge region caches 30 TB, a cross-region metadata read costs 180 ms p99 versus 5 ms regionally, and originals must be stored once. Which design meets 200 ms thumbnail and 2 s original p99 targets?
MCQ-5Three gateways (us-east, eu-west, ap-south) share a 1,000-token bucket refilled at 100/s, in a Redis primary in us-east: 1.5 ms from the local node, 40 ms from the other two. The 70/20/10 split is an average and inverts at the eu-west morning peak. Exceeding the bucket is a hard billing violation; rejecting up to 10% of what it allows is fine, and limiter overhead must stay under 5 ms p99 at every node. Which design meets all three?
MCQ-6A hit counter must return the number of hits in the last 300 seconds. Traffic is a sustained 50,000 hits/s and `getHits` is called once a minute. Design A keeps a `Deque<Long>` of every timestamp and prunes with `while (q.peekFirst() <= t - 300) q.pollFirst()` inside `getHits`; Design B keeps `int[300]` counts and `long[300]` stamps, indexing `t % 300` and zeroing a bucket whose stamp differs from `t`. Which statement about the two designs is correct?
MCQ-7A path between two flops in an 800 MHz domain (1.25 ns period) has launch clk-to-Q of 40 ps min and 90 ps max, and a logic cone of 200 ps min and 1050 ps max. The capture flop needs 70 ps of setup and 50 ps of hold, and its clock edge arrives 250 ps after the launch edge. Which statement about this path is correct?
MCQ-8`a = [1, 2, 4, 8, 16]` is sorted. A routine seeds a min-heap with every adjacent pair `(i, i+1)` keyed by `a[i+1]-a[i]`; on each of `k = 5` pops it emits `(i, j)` and pushes `(i, j+1)` and `(i+1, j)` whenever `i+1 < j` and `j+1 < 5`. Which pairs does it emit, in order?
MCQ-9A team clones a 5-node list (`next` plus `random`) in O(1) extra space by weaving each clone directly after its original, front to back, and setting `clone.random = original.random.next` inside that same pass, right after the insertion. The nodes hold values 1 to 5 in order, with randoms 1→4, 2→2, 3→1, 4→5, 5→3. Which clones end up with a wrong `random`?
MCQ-10A `flatten(root)` walks the BST in order with a `prev` pointer, sets `prev.right = node` and `node.left = prev` for each node after the first, records the first visited node as `head`, and after the walk sets `head.left = prev` and `prev.right = head`. On the BST whose in-order sequence is 1,2,3,4,5,6,7 it returns `head`; a reviewer then calls it on `null`. What is `head.left.val`, and what does the `null` call do?
MCQ-11A binary tree has root `20` with children `8` and `22`; `8` has children `4` and `12`, `22` has only a right child `25`, `4` has children `2` and `6`, and `12` has children `10` and `14`. A routine must return every node exactly 3 edges from the node holding `4`, so it adds parent pointers to make the tree undirected and runs BFS from `4` with a visited set. Which set of values does it return?
MCQ-12A subscription service in `America/New_York` classifies a billing period as exactly one month, less than one month, or more than one month apart, comparing dates on the local calendar. For `start = 2024-02-29T21:00:00-05:00` and `end = 2024-03-29T21:00:00-04:00`, which classification is right, and why?
MCQ-13A capacity-1 queue uses mutex `m` and condvars `not_full`/`not_empty`. Producers run `lock(m); if (count == 1) wait(m, not_full); buf = x; ++count; signal(not_empty); unlock(m);`; consumers run `lock(m); if (count == 0) wait(m, not_empty); y = buf; --count; signal(not_full); unlock(m);`. P1 pushes A, P2 calls push(B) and blocks, C pops A, then P1 pushes C before P2 reacquires `m`. What are `count` and `buf` afterward?
MCQ-14A 4-thread cyclic barrier uses one mutex, one condition variable, `int count = 0` and `unsigned generation = 0`. Each thread runs `lock(m); if (++count == 4) { count = 0; ++generation; broadcast(); } else while (count != 0) wait(m); unlock(m);`. T1 is released from round 0 and re-enters round 1; T4 re-enters next; T2 and T3 wake last. Which state results?
MCQ-15A trade store keeps 60 s of events in a `std::deque<Trade>` ordered by `(ts, seq)` under one `std::mutex`: writers `push_back` at 200k/s and a pruner every 50 ms calls `pop_front` while `front.ts < now - 60s`. `query(t0, t1)` binary-searches under the lock, unlocks, then walks from that iterator to `t1`; it crashes with a heap-use-after-free, and holding the lock across the walk instead pushes ingest p99 from 2 ms to 400 ms against a 5 ms budget. Which design fixes both?
MCQ-16A build tool orders 7 tasks with Kahn's algorithm: it seeds a FIFO queue with every zero-indegree task in alphabetical order and emits a task when its indegree reaches zero. The edges are `A→C`, `B→C`, `C→D`, `D→E`, `E→F`, `F→E` and `F→G`. Which outcome does the run produce?
MCQ-17Twelve Kafka partitions feed 3 consumers, 4 partitions each. Consumer C upserts its 12:00:30–12:00:45 slice of keyword `timeout` (180 counts) into Postgres keyed by (window, keyword, partition) with `ON CONFLICT DO UPDATE SET count = count + EXCLUDED.count`, then crashes before its 12:01:00 offset commit; its last commit was 12:00:30. It restarts and replays from there. The window's true count is 1,000. What does the aggregator's SUM report for that window, and why?
MCQ-18A decoder expands runs where a letter is followed by a decimal count (`a12b3` gives twelve `a`s then three `b`s), and a letter with no digits means one copy. A teammate's version returns `aabbb` for `a12b3` and `xx` for `x2y10`. Which defect in that version accounts for both results?
MCQ-19A 5-node doubly linked list holds values 1, 2, 1, 3, 2 in order; each node has `left` and `right`, and the head's `left` and the tail's `right` are `null`. A recursive `count(n)` returns `n == null ? 0 : 1 + count(n.left) + count(n.right)` and overflows the stack when called on the head. A teammate adds a `Set` of values, returning 0 when the current value is already present and otherwise adding it before recursing. What does the revised `count(head)` return?
MCQ-20A media service keeps each asset's row (version, sha256) in Postgres and its bytes in Redis under `blob:{id}`; hits must not read Postgres (4 ms from Redis, 40 ms from the row). The writer commits `UPDATE assets SET version = version + 1` then `DEL blob:{id}`; a reader that misses reads the row and, after a 2 s S3 range fetch, `SET`s the bytes. After a write, hits serve the new version with the old bytes until the 24 h TTL. Which change closes that window?
MCQ-21A nightly job reverses a 200,000-node singly linked list on Java 21 with a 1 MB thread stack (`-Xss1m`), using `Node rev(Node h) { if (h == null) return null; Node r = rev(h.next); h.next.next = h; h.next = null; return r; }`. The list is well-formed and non-empty. Which outcome does the job see?
MCQ-22Apple's final round asks 'Why this team?' for the on-device Siri personalization group. The manager's notes: next year is 70% eval and tooling, 30% model, because the ranker moves on-device and per-request logs go away; the 40 MB budget is settled. The candidate shipped a 30 MB on-device ranker, built the eval harness whose sampled counters caught a 4% NDCG drop after logs were cut, and ran a 200k QPS serving tier. Which answer fits?
MCQ-23A validator walks a 9×9 board of digits and `.`, skips `.`, and returns false on the first value repeated in a row, a column or a box, keying boxes as `(r % 3) * 3 + (c % 3)`. The board holds a 5 at (0,0) and a 5 at (3,3); every other cell is `.`. What does it return, and why?

Curated: · Written: · Reviewed: