Leaves Remaining After Wind Gusts
Problem statement
A rectangular garden is represented by garden. The value garden[r][c] is the number of leaves initially in cell (r, c).
Process every character of gusts from left to right. A gust shifts all leaves that are still present by one cell:
U: one row upD: one row downL: one column leftR: one column right
Leaves shifted outside the garden disappear permanently. Return the total number of leaves remaining after all gusts.
Function
remainingLeafSum(garden: int[][], gusts: String) → longExamples
Example 1
garden = [[1,2,3],[4,5,6]]gusts = "R"return = 12The rightmost column leaves the garden. The surviving original values are 1, 2, 4, and 5.
Example 2
garden = [[1,2],[3,4]]gusts = "UD"return = 7The upward gust permanently removes the first row. The following downward gust cannot restore it, so only values 3 and 4 remain.
Example 3
garden = [[5]]gusts = "L"return = 0The only leaves move beyond the left boundary.
Constraints
1 ≤ garden.length, garden[r].length ≤ 200- Every row has the same length.
0 ≤ garden[r][c] ≤ 10^90 ≤ gusts.length ≤ 200000gustscontains onlyU,D,L, andR.