1
class Solution {
2

3
public int totalSteps(int[] nums) {
4

5
int n = nums.length;
6
int ans = 0;
7

8
Stack<Pair<Integer, Integer>> st = new Stack();
9

10
st.push(new Pair(nums[n - 1], 0));
11

12
for (int i = n - 2; i >= 0; i--) {
13
int count = 0;
14

15
while (!st.isEmpty() && nums[i] > st.peek().getKey()) {
16
count = Math.max(count + 1, st.peek().getValue());
17
st.pop();
18
}
19

20
ans = Math.max(ans, count);
21
st.push(new Pair(nums[i], count));
22
}
23

24
return ans;
25
}
26
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0