You are given an integer height, an integer array positions, and a string directions representing the initial states of several pistons moving inside vertical chambers.
Each piston at index i has an initial vertical position positions[i] and an initial moving direction given by directions[i]:
'U' indicates that the piston is moving upward.
'D' indicates that the piston is moving downward.
Every second, each piston changes its position by
If a piston is at height and moving upward, it reverses its direction to downward.
If a piston is at
Otherwise, it continues moving in its current direction.
The total area occupied at any time is the sum of the positions of all pistons.
Return the maximum total area occupied by the pistons at any point in time.
Constraints:
height
positions.length directions.length
positions[i] height
directions[i] is either 'U' or 'D'.
You are given an integer height, an integer array positions, and a string directions representing the initial states of several pistons moving inside vertical chambers.
Each piston at index i has an initial vertical position positions[i] and an initial moving direction given by directions[i]:
'U' indicates that the piston is moving upward.
'D' indicates that the piston is moving downward.
Every second, each piston changes its position by
If a piston is at height and moving upward, it reverses its direction to downward.
If a piston is at
Otherwise, it continues moving in its current direction.
The total area occupied at any time is the sum of the positions of all pistons.
Return the maximum total area occupied by the pistons at any point in time.
Constraints:
height
positions.length directions.length
positions[i] height
directions[i] is either 'U' or 'D'.