Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let print = [];
- let index = 0;
- let max = Number.MIN_SAFE_INTEGER;
- for (let i = input.length - 1; i >= 0; i --) {
- if(input[i] > max) {
- max = input[i];
- print.push(input[i]);
- for (let j = ++i; j <= input.length; j++) {
- if (input[j] > max) {
- max = input[i];
- print.push(input[j]);
- }
- }
- }
- }
- console.log(print.reverse().join(" "));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement