FastPrepLeaves Remaining After Wind
Problems/Leaves Remaining After Wind

Leaves Remaining After Wind

Cresta logoCresta● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Cresta online assessment. The report is brief. It gives the leaf counts, the wind directions, and a total of leaves left. We chose that a leaf moves one cell and that leaves leaving the grid are lost for good. Our version is about 65% the same as the reported question.

A rectangular grid stores a nonnegative number of leaves in each cell. For this exercise, assume each character in winds moves every remaining leaf exactly one cell in that direction: U up, D down, L left and R right.

All leaves move simultaneously for each character. A leaf that moves outside the grid is permanently removed. Process the wind characters in order and return the total number of leaves still inside the grid. An empty wind string leaves the grid unchanged.

Function

remainingLeaves(grid: int[][], winds: String) → long

Examples

Example 1

grid = [[1,2],[3,4]]winds = "R"return = 4
grid
01012134

Only leaves initially in the left column survive, for a total of 1 + 3 = 4.

Example 2

grid = [[1,2],[3,4]]winds = "RL"return = 4
grid
01012134

The second wind moves surviving leaves back, but removed leaves do not return; the total is still 4.

Example 3

grid = [[5]]winds = ""return = 5
grid
005

No wind removes any leaf.

Constraints

  • 1 <= grid.length, grid[0].length <= 30; every row has the same length.
  • 0 <= grid[r][c] <= 10^9.
  • 0 <= winds.length <= 2000; characters are U, D, L or R.
  • Return the exact total as a signed 64-bit integer.

More Cresta interview questions

  • Decode Words with Anagram KeysOA · Seen Oct 2026
  • Find a File in a Directory SnapshotOA · Seen Oct 2026
  • Maximum Suffix–Prefix OverlapOA · Seen Oct 2026
  • Particle Moves to TargetOA · Seen Jul 2026
  • Rightward Bacteria ConsumptionOA · Seen Jul 2026
  • Top Three Companies by ProfitOA · Seen Jul 2026
  • Peak Chat Load Across AgentsPHONE SCREEN · Seen Nov 2026
  • File Storage ServicePHONE SCREEN · Seen Nov 2026
  • Dynamic Least-Loaded Job DispatcherPHONE SCREEN · Seen Oct 2026
  • Feature Flag Evaluation EngineONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Payment Partner RoutingStripe · OAStripe interview questions
  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Capping Portfolio WeightsCapstone Investment Advisors · OA
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
  • Stabilize Student Test ScoresVirtu Financial · OAVirtu Financial interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
  • Index of the Maximum After Left RotationsChubb · OAChubb interview questions
  • Rolling MetricsAkuna Capital · OAAkuna Capital interview questions

Cresta interview experiences

  • Cresta Senior SWE Coding Round Interview Experience: 1 Experience
All Cresta interview questionsSee Cresta hiring insights
Saved
class Solution {
    public long remainingLeaves(int[][] grid, String winds) {
        // write your code here
    }

}
Checking account…