Resilient Fake API Client
Reported by candidates from Tesla's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Tesla's Resilient Fake API Client showed up in reports from September 2026, and it's a simulation problem dressed up as an API question. The first attempt usually dies on a small detail, not on hard algorithms. You walk through responses in order, retry on 429 and 5xx, stop on anything else, and parse a tiny JSON-like body when you hit a 2xx. Nothing here is clever. It's a pile of edge cases that all have to be right at once. If you blank on the parser rules during the live OA, StealthCoder is the safety net running invisibly on your screen.
The problem
A fake API provides one response per attempt through parallel arrays statuses and bodies. Process at most maxAttempts responses in order.
A status from 200 through 299 is successful. Parse its body using the closed JSON grammar below. Return SUCCESS: followed by the object with keys sorted lexicographically, or JSON_ERROR when parsing fails.
Status 429 and every status from 500 through 599 are retryable while attempts remain.
Every other status is terminal; return HTTP_n, where n is the status.
If every permitted attempt is retryable, return EXHAUSTED.
An accepted body is exactly {} or a whitespace-free object such as {"b":"two","a":"1"}. Keys are unique, nonempty strings. Values may be empty. Key and value characters are limited to ASCII letters, digits, underscores, and hyphens. Escapes, nesting, arrays, numbers, booleans, null, and whitespace are invalid.
Function
handleResponses(statuses: int[], bodies: String[], maxAttempts: int) → String
Examples
Example 1
statuses = [429,503,200]
bodies = ["ignored","ignored","{\"b\":\"two\",\"a\":\"1\"}"]
maxAttempts = 3
return = "SUCCESS:{\"a\":\"1\",\"b\":\"two\"}"
The client retries the rate limit and server failure. The successful body is valid and its keys are canonicalized.
Example 2
statuses = [500,429,503,200]
bodies = ["","","","{}"]
maxAttempts = 3
return = "EXHAUSTED"
Only three attempts are permitted, and all three observed statuses are retryable. The later success is not consumed.
Example 3
statuses = [200]
bodies = ["{\"a\": \"b\"}"]
maxAttempts = 1
return = "JSON_ERROR"
Whitespace is outside the accepted grammar, so a successful HTTP status still produces a parse error.
Constraints
1 <= statuses.length == bodies.length <= 100000.
1 <= maxAttempts <= statuses.length.
100 <= statuses[i] <= 599.
0 <= bodies[i].length <= 1000.
A body is parsed only for the first successful status.
Accepted object keys are unique and the total output fits in memory.Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is plain simulation plus a hand-written parser. Loop i from 0 to maxAttempts-1. If status is 2xx, parse bodies[i] and return immediately, success or JSON_ERROR. If it's 429 or 5xx, continue. Anything else returns HTTP_n. If the loop finishes, return EXHAUSTED. The pitfall that sinks first attempts is looking past maxAttempts, as Example 2 shows, where the later 200 must not be consumed. The second pitfall is parsing loosely. Don't reach for a JSON library, because whitespace, escapes and numbers must fail. Check the braces, split on commas, split each pair on the quote-colon-quote pattern, validate characters against letters, digits, underscore and hyphen, reject empty keys and duplicate keys, then sort keys and rebuild. If the parser rules slip your mind mid-assessment, StealthCoder gives you a working version in real time.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Resilient Fake API Client 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 Tesla's OA.
Tesla 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.
Resilient Fake API Client FAQ
What's the trick in Tesla's Resilient Fake API Client?+
There isn't a deep algorithm. It's careful simulation. Iterate only up to maxAttempts, classify each status, and return on the first terminal or successful response. Most failures come from parsing the body wrong or reading past the attempt limit, not from the retry logic itself.
Can I just use a JSON library for the body?+
No. The grammar is stricter than JSON. Whitespace, escapes, nesting, numbers, booleans and null must all produce JSON_ERROR. A library would accept inputs the problem rejects. Write a small manual parser that checks characters and structure directly.
What edge cases should I test?+
Test {} as valid, an empty value like {"a":""}, an empty key, duplicate keys, a trailing comma, and whitespace anywhere. Also test maxAttempts smaller than the array length, a 2xx that arrives after the limit, and a 3xx or 4xx other than 429 returning HTTP_n.
How do I handle the body only being parsed once?+
Parse only at the first 2xx status you reach within the attempt limit, then return right away. Retryable responses never touch their body, so ignore those strings completely. This also keeps the work linear in total body length.
How do I prepare for this in 48 hours?+
Write the parser once from scratch and run the three examples plus your own edge cases. Practice sorting keys and rebuilding the string with exact quote and colon placement. Simulation problems like this reward clean, tested code more than speed.