Vassil_Iliev

longest increased squence

Mar 23rd, 2022
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let input = ['8',
  2.     '1',
  3.     '2',
  4.     '3',
  5.     '4',
  6.     '1',
  7.     '2',
  8.     '3',
  9.     '4']
  10.  
  11. let print = this.print || console.log;
  12. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  13.  
  14. let length = +gets();
  15. let arr = [];
  16. for(let i =0 ; i<length; i++){
  17.     arr.push(+gets())
  18. }
  19.  
  20. let index = 1;
  21. let count = 0;
  22. let tempCount = 0;
  23. for(let i = 1; i < arr.length; i++){
  24.    
  25.     if(arr[i-1] < arr[i]){
  26.         tempCount++
  27.    
  28.     }else{
  29.        
  30.         if(tempCount > count){
  31.             count = tempCount;
  32.             tempCount = 0;
  33.         }else{
  34.             tempCount = 0;
  35.         }
  36.     }
  37. }
  38. print(count+1);
Advertisement
Add Comment
Please, Sign In to add comment