Max Index

Problem Overview

  • Compute the maximum index reachable on an infinite array starting at 0 after a given number of steps.
  • Each step t (from 1), you may stay or move i -> i + j; j starts at 1 and increments by 1; a single bad index must be avoided.
  • Input: steps (1 ≤ steps ≤ 2×10^3) and badIndex; Output: maximum reachable index without landing on badIndex.
  • Real-world context: path planning with growing jumps while avoiding a blocked position; classic coding interview problem.
  • This interview question comes from IBM interviews.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: