Ctrl K

Tipped Crate of Stones

Medium
A crate is drawn from the side as a grid crate with m rows and n columns. Each cell holds one of: - '#': a stone; - '*': a shelf fixed firmly inside the crate; - '.': empty space. The crate is tipped onto its right side, i.e. turned 90° clockwise. After the turn, gravity pulls the stones down until each one rests on a shelf, on another stone or on the floor of the crate. Shelves stay where they are, and stones fall straight down without drifting sideways. Return the picture of the crate after the turn and the fall: a grid with n rows and m columns.
Example 1
crate=[["#", "#", ".", "*", "#", "."]] → [['.'], ['#'], ['#'], ['*'], ['.'], ['#']]

After the turn the row becomes a column whose bottom is its old right end. The two left stones slide down onto the shelf *, the right stone drops to the floor.

Example 2
crate=[[".", "#"], ["#", "."]] → [['.', '.'], ['#', '#']]

The bottom row of the crate becomes the left column and the top row becomes the right one. In both columns the stone ends up on the floor.

Constraints
  • 1 ≤ m, n ≤ 500
  • All rows of crate have the same length n
  • crate[i][j] is one of '#', '*', '.'
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMatch-Three Cascade MediumMirror Rows or Columns MediumMirrored Board in Fours MediumMirror and Negate a Bitmap EasyHow Far the Water Spreads Hard
loading Python…
Input
crate=[["#", "#", ".", "*", "#", "."]]
Expected
[['.'], ['#'], ['#'], ['*'], ['.'], ['#']]

Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.