0 to height top.
You are given an array levels, where levels[i] is the current height of rod i, and a string moves, where moves[i] is its direction: 'U' for up, 'D' for down.
Every second each rod moves by 1 in its direction. As soon as a rod is at height 0 or top, its direction flips (a rod sitting at an end and facing outward goes back on the next second).
Return the largest total height of all rods that is ever reached, the current moment included.top=4, levels=[1, 3], moves="UD" → 4
The total is 1 + 3 = 4 now and never changes: one rod rises while the other sinks, and they bounce off the ends at the same moments. The answer is 4.
top=5, levels=[0, 2, 5], moves="UUD" → 10
After 3 seconds the rods stand at 3, 5 and 2, a total of 10, and no moment does better.
top=3, levels=[3, 0, 0], moves="DDD" → 6
top ≤ 10⁶top'U' or 'D'top=4, levels=[1, 3], moves="UD"
4
Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.