Atlassian Coding Interview: Snake on a Board
Based on questions reported for Atlassian interviews
The interviewer opens
Hi, and thanks for joining. Welcome to your interview for the software engineer role at Atlassian. We'll work through one coding problem together, and I'd like you to think out loud as you code. If you need to step out or take a break, you can pause any time with the Pause button at the top right.
The problem is a small game simulation about moving a snake around a board, and it's in the Problem tab on the right. Please read it through, take your time, and ask me any questions before you start.
The problem
Build a SnakeGame class with next_move(direction); play_snake creates a game and replays the moves.
height,width: board size.food: list of{row, col}, appearing one at a time in order.moves: list of"U","D","L","R".
The snake starts at (0,0) as one cell; each move shifts the head one cell. Eating the current food scores +1, reveals the next food and grows the snake (its tail stays put); otherwise the tail moves up. If the head would leave the board, the game ends; that move and all later ones are ignored. Return {score, game_over, body}, body head to tail.
Example: height=3, width=3, food=[(0,1),(1,1)], moves=[R,D,D] → score 2, game_over false, body [(2,1),(1,1),(0,1)].
Up to 10^4 moves and food items.