Skip to content

Practice Rotating the Box

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1861
LeetCode Problem

Rotating the Box

Problem Statement

In boxGrid, # is a stone, * a fixed obstacle, and . an empty cell. Rotate the m by n box 90 degrees clockwise, then let stones fall downward until blocked by an obstacle, another stone, or the box boundary. Obstacles stay fixed relative to the rotated box, and rotation adds no sideways movement to stones. Initially every stone is supported by another stone, an obstacle, or the bottom. Return the resulting n by m matrix.

Source: Rotating the Box on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
boxGrid = [["#",".","#"]]
Output
[["."], ["#"], ["#"]]

# Example 2

Input
boxGrid = [["#",".","*","."], ["#","#","*","."]]
Output
[["#","."], ["#","#"], ["*","*"], [".","."]]

# Example 3

Input
boxGrid = [["#","#","*",".","*","."], ["#","#","#","*",".","."], ["#","#","#",".","#","."]]
Output
[[".","#","#"], [".","#","#"], ["#","#","*"], ["#","*","."], ["#",".","*"], ["#",".","."]]

Constraints

m == boxGrid.length
n == boxGrid[i].length
1 <= m, n <= 500
boxGrid[i][j] is either '#', '*', or '.'.

Related LeetCode Problems

Practice more problems similar to Rotating the Box.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.