DimiPetrov

Longest Sequence of Equal (updated)

Jan 9th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. let input = ['10', '2', '1', '1', '2', '3', '3', '2', '2', '2', '1'];
  2. let print = this.print || console.log;
  3. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  4.  
  5. const n = +gets();
  6.  
  7. let maxCount = 1;
  8.  
  9. for(let i = 0; i < n; i++) {
  10. const arr = gets().split(', ').map(Number);
  11. let count = 1;
  12. let elToCompare = arr[i];
  13. for(let j = i + 1; j < n; j++) {
  14. let el = arr[j];
  15. if(el === elToCompare) {
  16. count++;
  17. } else {
  18. break;
  19. }
  20. }
  21.  
  22. if(count > maxCount) {
  23. maxCount = count;
  24. }
  25. }
  26.  
  27. print(maxCount);
Advertisement
Add Comment
Please, Sign In to add comment