Snake Movement Simulation

Company: flipkart_8aug

Difficulty: medium

Problem Statement

Snake Movement Simulation Problem Description In a video game, a snake moves inside a two-dimensional square grid by following a fixed list of instructions. As the snake moves, it leaves a trail of poison on every point it passes through. If the snake ever steps onto that trail again, the poison kills it and the game ends. The game also ends if the snake falls off the grid. The grid represents the first quadrant of the Cartesian plane: (0, 0) is at the bottom left of the grid, x increases to the right and y increases upwards. A grid of width W and height D contains every point (x, y) with 0 <= x <= W and 0 <= y <= D . (inferred -- the source places (0, 0) on the grid, and its Example 2 shows that y = D is still on the grid while y = D + 1 is off it; both edges are therefore inclusive.) The snake starts at (x, y) facing east (the direction of the positive x-axis). The route is a list of n moves, each written as a turn letter T followed by a distance K : S means keep going st