Write a function that takes the grid and the wind string as input, and returns the total numbers of leaves remaining on the grid after all wind events have occurred. Example: Input: Grid: [[1, 0, 2], [4, 1, 0], [0, 3, 1]], Wind: “RR” Output: 4
Asked in the online_assessment stage. One of the CoderPad OA problems, candidate passed correctness tests but not fully optimized within the time limit.
For grading, each wind character removes one outermost column. R removes the rightmost remaining column and L removes the leftmost remaining column. If consecutive wind characters are identical, the removal side alternates, so RR removes the rightmost column and then the leftmost column. Return the sum of all values in columns that remain. The grid is rectangular, and an event after all columns have been removed has no effect.
L or Rdef remaining_leaves(grid, wind):