You are given an grid of characters. Each cell contains either a lowercase letter, the symbol '#' (which acts as an immovable barrier), or '.' (which represents an empty slot). Your task is to perform two operations on this grid, in order:
'#' or another character that has already settled. Barriers themselves never move. Empty cells '.' serve only as open space through which characters can fall.Return the final grid after both the rotation and the gravity simulation.
Example 1:
Input:
n = 3, grid =
["c..",
"#.b",
".a."]
Output:
[".#.",
"...",
"abc"]
Explanation: Rotating the grid 90° clockwise produces [".#c", "a..", ".b."]. Gravity then works column by column: "a" (column 0) falls to the bottom row, "b" (column 1) is already on the bottom row and the "#" above it never moves, and "c" (column 2) falls all the way to the bottom. The bottom row becomes "abc".
grid = ['c..', '#.b', '.a.']['.#.','...', 'abc']
We start with the original 3×3 grid. 'c', 'a', 'b' are movable letters, '#' is an immovable barrier, and '.' are empty slots.
Example 2:
Input:
n = 4, grid =
["..#.",
"a...",
"#.z.",
"...."]
Output:
[".#..",
"....",
"...#",
".za."]
Constraints:
1 <= n <= 100grid has length n.'.', '#', and lowercase English letters ('a' to 'z').grid = ['c..', '#.b', '.a.']['.#.','...', 'abc']
We start with the original 3×3 grid. 'c', 'a', 'b' are movable letters, '#' is an immovable barrier, and '.' are empty slots.