0 day streak
Anonymous · shared experience1 Oct 2025 · 8 views

Apple: Sum a long iterator's values, then split the work across two threads

Interview question #Apple DSA / coding

Problem. You are handed a custom iterator over long values. Internally it starts at 0, stops at one million, reports whether more values remain, and returns the next incremented value on each call. Write a driver that consumes the iterator and returns the total of every value it produces.

Follow-up. Make the sum run in parallel on two threads. The candidate used an executor service, a completable future and an atomic long, and the interviewer seemed satisfied.

Further discussion. The interviewer then asked why an executor service is better than creating raw threads, went over SOLID principles and Spring basics (MVC versus Boot, inversion of control), and posed a production scenario: a service that keeps crashing every two hours after a deploy, and what you would do.

What mattered. Concurrency and safe sharing of state between threads were the core of the round, followed by debugging instincts in production. A later onsite round asked a warehouse producer-consumer problem where four threads place cars into single-car slots.

0 comments

Comments 0

No comments yet. Ask the author something, or add what happened in your own round.