Advertisement
Spocoman

05. Max Number

Jan 22nd, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3.     let print = [];
  4.     let index = 0;
  5.     let max = Number.MIN_SAFE_INTEGER;
  6.  
  7.     for (let i = input.length - 1; i >= 0; i --) {
  8.         if(input[i] > max) {
  9.             max = input[i];
  10.             print.push(input[i]);
  11.  
  12.             for (let j = ++i; j <= input.length; j++) {
  13.                 if (input[j] > max) {
  14.                     max = input[i];
  15.                     print.push(input[j]);
  16.                 }
  17.             }
  18.         }
  19.     }
  20.     console.log(print.reverse().join(" "));
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement