Push and Fall Boxes
You are given a matrix of characters representing a board. Each cell of the matrix contains one of three characters:
You decide to do the following operations:
Given board, a matrix representation of the board, your task is to return the state of the board after the push and fall operations.
Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(board.length * board[0].length * min(board.length, board[0].length)) will fit within the execution time limit.
1Example 1
After pushing the boxes to the right, the board state will be:
[["#","#",".",".","*",".",".","#","."],
[".",".",".",".",".",".","*",".","."],
[".",".",".",".",".",".",".",".","."],
["#",".",".","#",".",".",".",".","#"]]
After pushing the boxes down, the board state will be:
[[".",".",".",".","*",".",".",".","."],
[".",".",".",".",".",".","*",".","."],
[".",".",".",".",".",".",".",".","."],
["#","#","#","#",".",".",".","#","#"]]
2Example 2
After pushing the boxes to the right, the board state will be:
[["#",".",".",".",".",".",".",".","."],
[".","#",".",".",".",".",".",".","."],
[".",".","#",".",".",".",".",".","."],
[".",".",".","#",".",".",".",".","."],
[".",".",".",".","#",".",".",".","."],
[".",".",".",".",".","#",".",".","."],
[".",".",".",".",".",".","#",".","."],
[".",".",".",".",".",".",".","#","."],
["*","*","*","*","*","*","*","*","#"]]
After pushing the boxes down, the board state will be:
[[".",".",".",".",".",".",".",".","."],
[".",".",".",".",".",".",".",".","."],
[".",".",".",".",".",".",".",".","."],
[".",".",".",".",".",".",".",".","."],
[".",".",".",".",".",".",".",".","."],
[".",".",".",".",".",".",".",".","."],
["#",".",".",".",".",".",".",".","."],
["*","*","*","*","*","*","*","#","#"]]