Pipe Removal Turns
Problem statement
Pipes are arranged from left to right, and lengths[i] is the length of pipe i.
During each turn, mark every pipe whose length is strictly greater than the pipe immediately to its left. Remove all marked pipes simultaneously.
Repeat until a turn marks no pipes. Return the number of turns in which at least one pipe is removed.
Function
countPipeRemovalTurns(lengths: int[]) → intExamples
Example 1
lengths = [3,6,9,8]return = 2Turn 1 removes 6 and 9, leaving [3,8]. Turn 2 removes 8, leaving [3].
Example 2
lengths = [9,7,5,3]return = 0No pipe is longer than the pipe immediately to its left.
Example 3
lengths = [4,3,7,5,6,4,2]return = 3The successive stable lists are [4,3,5,4,2], [4,3,4,2], and [4,3,2].
Constraints
2 <= lengths.length <= 10^5.1 <= lengths[i] <= 10^9.