First Successful Concurrent API Result Before a Timeout
Reported by candidates from Apple's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The detail that matters in this Apple OA, reported September 2026, is the word "inclusive" hiding in Example 2: a call finishing at exactly 50 ms with a 50 ms timeout still counts. That's the whole trap. The problem looks like concurrency, but there's no threading here. It's a single array scan with a filter and a tiebreak. If you've got an invite and 48 hours, this one is quick to nail down. StealthCoder sits invisibly as a safety net on the live OA if your mind goes blank on the edge cases, but you shouldn't need it once you see the shape.
The problem
All backend calls start concurrently at time 0. Call i completes after latencies[i] milliseconds, succeeds exactly when succeeds[i] is true, and yields values[i]. Return the value of the successful call with the smallest completion time that finishes no later than the shared timeoutMs. If several successful calls finish together, choose the smaller input index. Return the empty string when no successful call finishes before the timeout. Function firstSuccessfulResult(latencies: int[], succeeds: boolean[], values: String[], timeoutMs: int) → String Examples Example 1 latencies = [120,40,75] succeeds = [true,false,true] values = ["slow","error","winner"] timeoutMs = 100 return = "winner" The call at 40 ms fails. The call at 75 ms is the first success before the timeout. Example 2 latencies = [50,50,10] succeeds = [true,true,false] values = ["left","right","bad"] timeoutMs = 50 return = "left" The two successful calls tie at the inclusive timeout, so the smaller index wins. Example 3 latencies = [5,90] succeeds = [false,true] values = ["x","y"] timeoutMs = 80 return = "" The early call fails and the successful call completes too late. Constraints 1 <= latencies.length <= 100000. succeeds.length = values.length = latencies.length. 0 <= latencies[i], timeoutMs <= 10^9. Each value contains at most 200 visible ASCII characters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is a linear scan with a running best. Loop through every index. Skip calls where succeeds[i] is false. Skip calls where latencies[i] is greater than timeoutMs, since equal is allowed. Among the survivors, keep the one with the smallest latency. On a tie, keep the earlier index. If you iterate left to right and only replace the best when latency is strictly smaller, the tiebreak takes care of itself. Track the best index, start it at -1, and return the empty string if it never changes. The common pitfalls are using a strict less-than against the timeout, replacing on equal latency so the later index wins, and returning null instead of an empty string. Sorting works but costs O(n log n) for no reason. With n up to 100000, O(n) is the clean answer. If you freeze on the live OA, StealthCoder is the hedge that surfaces this scan fast.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill First Successful Concurrent API Result Before a Timeout cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Apple's OA.
Apple reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
First Successful Concurrent API Result Before a Timeout FAQ
How hard is this Apple OA question really?+
Easy. It's a single pass over three parallel arrays with a filter and a tiebreak. The difficulty is reading carefully, not algorithms. Most misses come from the inclusive timeout or the tie rule, not from the approach itself.
What's the trick to the timeout boundary?+
The timeout is inclusive. A successful call with latency equal to timeoutMs counts. Use latencies[i] <= timeoutMs, not strictly less. Example 2 exists to test exactly this, so check it against your code before submitting.
How do I handle ties between successful calls?+
Scan left to right and only update your best candidate when the new latency is strictly smaller than the current best. Equal latencies then keep the earlier index automatically. No extra comparison on index is needed, which keeps the code short and bug-free.
Do I need to sort or use a heap?+
No. Sorting gives O(n log n) and a heap adds complexity for nothing. One O(n) loop tracking the best index is enough for 100000 elements. Sorting also forces you to carry indexes for the tiebreak, which invites mistakes.
What should I return when nothing qualifies?+
Return the empty string, not null. Keep a bestIndex starting at -1 and check it at the end. Example 3 covers the case where the only success arrives after the timeout, so test that one and the all-failures case before submitting.