From 2f8823ca54630046cbf2bd8291a0754197a4a0d1 Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Tue, 4 Mar 2025 17:11:19 -0500 Subject: [PATCH] Create README - LeetHub --- 3248-snake-in-matrix/README.md | 161 +++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 3248-snake-in-matrix/README.md diff --git a/3248-snake-in-matrix/README.md b/3248-snake-in-matrix/README.md new file mode 100644 index 0000000..b643dc8 --- /dev/null +++ b/3248-snake-in-matrix/README.md @@ -0,0 +1,161 @@ +
There is a snake in an n x n matrix grid and can move in four possible directions. Each cell in the grid is identified by the position: grid[i][j] = (i * n) + j.
The snake starts at cell 0 and follows a sequence of commands.
+ +You are given an integer n representing the size of the grid and an array of strings commands where each command[i] is either "UP", "RIGHT", "DOWN", and "LEFT". It's guaranteed that the snake will remain within the grid boundaries throughout its movement.
Return the position of the final cell where the snake ends up after executing commands.
+
Example 1:
+ +Input: n = 2, commands = ["RIGHT","DOWN"]
+ +Output: 3
+ +Explanation:
+ +| 0 | +1 | +
| 2 | +3 | +
| 0 | +1 | +
| 2 | +3 | +
| 0 | +1 | +
| 2 | +3 | +
Example 2:
+ +Input: n = 3, commands = ["DOWN","RIGHT","UP"]
+ +Output: 1
+ +Explanation:
+ +| 0 | +1 | +2 | +
| 3 | +4 | +5 | +
| 6 | +7 | +8 | +
| 0 | +1 | +2 | +
| 3 | +4 | +5 | +
| 6 | +7 | +8 | +
| 0 | +1 | +2 | +
| 3 | +4 | +5 | +
| 6 | +7 | +8 | +
| 0 | +1 | +2 | +
| 3 | +4 | +5 | +
| 6 | +7 | +8 | +
+
Constraints:
+ +2 <= n <= 101 <= commands.length <= 100commands consists only of "UP", "RIGHT", "DOWN", and "LEFT".