Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void solution(int n, int[] nums) {
- Stack<Integer> stack = new Stack<>();
- int highestJump = 0;
- int[] jumpPerNum = new int[n];
- for(int i = 0; i < n; i++){
- int currNum = i;
- stack.push(nums[currNum]);
- int count = n - 1;
- while (currNum < count) {
- if(nums[currNum + 1] > stack.peek()) {
- stack.push(nums[currNum + 1]);
- }
- if(nums[count] < stack.peek()) {
- count--;
- }
- currNum++;
- }
- jumpPerNum[i] = stack.size() - 1;
- if(highestJump < jumpPerNum[i]) {
- highestJump = jumpPerNum[i];
- }
- stack.clear();
- }
- System.out.println(highestJump);
- System.out.println(Arrays.toString(jumpPerNum));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement