Maximum Index
Updated
Problem statement
You have an endless row of positions numbered 0, 1, 2, .... A pointer starts at index 0.
You take steps steps, numbered 1 to steps. On step j, the pointer either moves forward by exactly j or stays where it is. The step number goes up by one each time, even when the pointer stays.
The pointer must never land on index badIndex. Return the highest index the pointer can be at after all steps steps.
Function
maxIndex(steps: int, badIndex: int) → intExamples
Example 1
steps = 4badIndex = 6return = 9Moving on every step would visit 1, 3 and then 6, which is not allowed. One plan moves on steps 1 and 2 to reach 3, stays on step 3, and moves 4 on step 4 to reach 7. A better plan stays at 0 on step 1, then moves to 2, 5 and 9. The highest index you can reach is 9.
Example 2
steps = 2badIndex = 2return = 3Move on both steps: 0 + 1 = 1, then 1 + 2 = 3. Neither stop is index 2, so the answer is 3.
Example 3
steps = 2badIndex = 1return = 2Moving on step 1 would land on the bad index 1. So stay at 0 on step 1, then move 2 on step 2 to reach index 2.
Example 4
steps = 3badIndex = 3return = 5Moving on every step would visit 1 and then 3, which is not allowed. Staying on step 2 gives 1, 1, 4. Staying on step 1 gives 0, 2, 5. The best is 5.
Constraints
1 <= steps <= 2 * 1031 <= badIndex <= 4 * 106
More Airbnb Online Assessment questions
- Task Management SystemOA · Seen Nov 2026
- Recipe Management SystemOA · Seen Nov 2026
- Progressive Banking SystemOA · Seen Nov 2026
- Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
- Parcel Attribute Store with TTLOA · Seen Oct 2026
- Parcel Event TrackingOA · Seen Oct 2026
- Median Home Price by CityOA · Seen Sep 2026
- In-Memory File SystemOA · Seen Sep 2026
- Worker Management (Promotion Track), Part 4: Full-Shift Double PayOA · Seen Sep 2026
- Worker Management (Promotion Track), Part 3: Promotions and SalaryOA · Seen Sep 2026
Similar questions at other companies
- Server InvestmentRippling · OARippling interview questions
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
- Particle Moves to TargetCresta · OACresta interview questions
- Digit Changes for a Multiple of 9Nutanix · OANutanix interview questions
- Warehouse Allocation (Distribute)Amazon · OA
- Find Maximum Even SumIBM · OAIBM interview questions
- Server InvestmentSnowflake · OASnowflake interview questions
- Calculate ChangePayPay · OAPayPay interview questions
- Delete and Freeze GameRubrik · OARubrik interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
Interview reports that mention this question
Airbnb interview experiences
- Airbnb SWE OA: Four-Level Banking System: 1 Experience
- 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, Diplomacy Game: 19 Experiences (Part 4 of 7)