Configurable Retry Strategies
Updated
Problem statement
You are simulating a client that retries a request. The list outcomes gives the result of each attempt, in order. Each outcome is either FAILURE or SUCCESS:value.
The client uses one retry strategy:
ONCEallows at most one retry after the first attempt, even whenmaxRetriesis larger. It waitsbaseDelaymilliseconds before that retry. IfmaxRetriesis zero,ONCEmakes no retry.FIXEDallows at mostmaxRetriesretries. It waitsbaseDelaymilliseconds before each retry.EXPONENTIALallows at mostmaxRetriesretries. The retries are numbered fromk = 1. Before retry numberk, it waitsbaseDelay * 2^(k - 1)milliseconds.
Go through outcomes from left to right. The first attempt starts at elapsed time 0. Stop at the first success, or when the strategy allows no more retries. The input always has enough outcomes for every attempt the strategy allows.
If an attempt succeeds, return SUCCESS:value|attempts|elapsed. If every allowed attempt fails, return FAILED|attempts|elapsed. Here attempts counts every attempt made, including the first one. elapsed is the total of the waits before the retries that actually ran.
Function
simulateRetries(outcomes: String[], strategy: String, maxRetries: int, baseDelay: long) → StringExamples
Example 1
outcomes = ["FAILURE","SUCCESS:ok"]strategy = "ONCE"maxRetries = 5baseDelay = 10return = "SUCCESS:ok|2|10"The first attempt fails. ONCE allows one retry, which runs after a 10-millisecond wait. That retry succeeds, so the answer reports two attempts and that one wait as the elapsed time.
Example 2
outcomes = ["FAILURE","FAILURE","SUCCESS:ready","FAILURE"]strategy = "EXPONENTIAL"maxRetries = 3baseDelay = 5return = "SUCCESS:ready|3|15"The first two attempts fail. The two retries that run wait 5 and then 10 milliseconds. The third attempt succeeds, after 15 milliseconds in total.
Example 3
outcomes = ["FAILURE","FAILURE","SUCCESS:late","FAILURE"]strategy = "ONCE"maxRetries = 3baseDelay = 7return = "FAILED|2|7"The first attempt fails. ONCE allows only one retry, and that retry fails too. The client stops there and returns FAILED, so the later success is never checked.
Constraints
strategyisONCE,FIXED, orEXPONENTIAL.0 <= maxRetries <= 30.1 <= baseDelay <= 10^6.outcomes.lengthis at least the maximum number of attempts allowed by the selected strategy.- Every outcome is exactly
FAILUREor begins withSUCCESS:. - Every elapsed-time result fits in a signed 64-bit integer.
More Airbnb Online Assessment questions
- Bouncing DiagonalsOA · Seen Dec 2026
- Count Numbers Not Equal to the First TwoOA · Seen Dec 2026
- Garden Sprinkler PlacementOA · Seen Dec 2026
- Theme Park Shuttle Wait TimeOA · Seen Dec 2026
- Count Card Duel RoundsOA · Seen Nov 2026
- Count Lamps Lighting Each PointOA · Seen Nov 2026
- Simulate Orchard Rot SpreadOA · Seen Nov 2026
- Sort Adjacent PairsOA · Seen Nov 2026
- In-Memory File SystemOA · Seen Nov 2026
- Task Management SystemOA · Seen Nov 2026
Similar questions at other companies
- Last Object Exit TimeIBM · OAIBM interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Bold Play to Reach a GoalSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Find Total CostJP Morgan Chase · OAJP Morgan Chase interview questions
- Macaron Order PriceOpenAI · OAOpenAI interview questions
- Daily Settlement for Long and Short PositionsBelvedere Trading · OA
- Debug the Risk-Limit QuoterMillennium · OAMillennium interview questions
- Prime Factor VisitationMaven Securities · OAMaven Securities interview questions
Airbnb interview experiences
- Airbnb OA · November 2026
- Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
- Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
- Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
- Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
- Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)