medium

Design a Snake Game

Design the classic snake game. Include a board with the snake, food placement, movement with direction changes, collision detection (walls and self), scoring, and game-over logic.

Suggested time: 45 minutes

Loading the workspace...

About this problem

A snake game seems trivially simple: move, eat, grow, die. But underneath, the system must handle input from a separate thread without corrupting game state, detect collisions in O(1) using a HashSet, manage a game loop with state transitions, and support extensible food types. Let's break this down.

What your design needs to cover

  • Directional Movement

  • Eat Food and Grow

  • Collision Detection and Game Over

  • Score Tracking

Key challenges the editorial covers

Learn from other designs

Related problems

Guides