Snakes and Ladders
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an n x n board. Squares are numbered 1 to n² in a zig-zag (boustrophedon) pattern starting at the **bottom-left**: the bottom row runs left to right, the row above runs right to left, and the direction alternates on each row going up.
You start on square 1. Each move, pick a destination square next in [curr + 1, min(curr + 6, n²)] (you choose the die result). If the cell for next holds a value board[r][c] != -1, that is a snake or ladder, and you are moved to square board[r][c]. You follow at most **one** snake or ladder per move, even if the square you land on starts another one.
Return the minimum number of moves needed to reach square n², or -1 if it cannot be reached. Squares 1 and n² never hold a snake or ladder.
Examples
Constraints
- n == board.length == board[i].length
- 2 <= n <= 20
- board[i][j] is -1 or in the range [1, n²]
- The cells for squares 1 and n² hold -1
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.