You are given an m x n matrix of characters boxGrid representing a side-view of a box. Each cell of the box is one of the following: A stone '#' A stationary obstacle '*' Empty '.' The box is rotated 90 degrees clockwise, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity does not affect the obstacles' positions, and the inertia from the box's rotation does not affect the stones' horizontal positions. Return an n x m matrix representing the box after the rotation described above.
Example 1
Input: boxGrid = [["#",".","#"]]
Output: [["."],["#"],["#"]]
Explanation: Before rotating, gravity will pull the stones toward the right end of the row, so the row becomes [".","#","#"]. Rotating clockwise turns that row into a column with the empty cell on top.
Example 2
Input: boxGrid = [["#",".","*","."],["#","#","*","."]]
Output: [["#","."],["#","#"],["*","*"],[".","."]]
Explanation: In the first row, the stone slides right until it stops against the obstacle, giving [".","#","*","."]. The second row's stones already rest on its obstacle. Rotating clockwise turns each column of the original box into a row of the answer.
Example 3
Input: boxGrid = [["#","#","*",".",".","*","."],["#","#","#","*",".",".","."]]
Output: [["#","#"],["#","#"],["#","*"],["*","."],[".","."],[".","*"],[".","."]]
Explanation: In both rows every stone already rests against an obstacle, so nothing moves. The answer is just the box rotated 90° clockwise.
After rotation, what was the right edge of each row becomes the bottom of each column — so gravity in the rotated box pulls stones in that direction. Solve it in the original orientation by sliding stones rightward, then rotate as a final step.
Run checks all cases above. Submit evaluates all test cases.