1class Solution {23public int totalSteps(int[] nums) {45int n = nums.length;6int ans = 0;78Stack<Pair<Integer, Integer>> st = new Stack();910st.push(new Pair(nums[n - 1], 0));1112for (int i = n - 2; i >= 0; i--) {13int count = 0;1415while (!st.isEmpty() && nums[i] > st.peek().getKey()) {16count = Math.max(count + 1, st.peek().getValue());17st.pop();18}1920ans = Math.max(ans, count);21st.push(new Pair(nums[i], count));22}2324return ans;25}26}