3279. Maximum Total Area Occupied by Pistons
There are several pistons in an old car engine, and we want to calculate the maximum possible area under the pistons.
You are given:
- An integer
height
- An integer array
positions
, wherepositions[i]
is the current position of pistoni
- A string
directions
, wheredirections[i]
is the current moving direction of pistoni
,'U'
for up, and'D'
for down.Each second:
- Every piston moves in its current direction 1 unit. e.g., if the direction is up,
positions[i]
is incremented by 1.- If a piston has reached one of the ends, i.e.,
positions[i] == 0
orpositions[i] == height
, its direction will change.Return the maximum possible area under all the pistons.
1 |
|