bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
MediumArrays & HashingLC 353

Design Snake Game

Design a Snake game) that is played on a device with screen size height x width. Play the game online if you are not familiar with the game. The snake is initially positioned at the top left corner (0, 0) with a length of 1 unit. You are given an array food where food[i] = (ri, ci) is the row and column position of a piece of food that the snake can eat. When a snake eats a piece of food, its length and the game's score both increase by 1. Each piece of food appears one by one on the screen, meaning the second piece of food will not appear until the snake eats the first piece of food.

Asked at 8 companies
AmazonAppleBloomberg
Hints
  • 1.Think about which data structure fits best
  • 2.Consider the time complexity of your approach
  • 3.Look for patterns in the constraints
LeetCode