BoGeo

Longest Sequence of Equal - Judge

Oct 4th, 2019
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. const n = +gets();
  2. const arr = new Array(n);
  3. const j = +gets();
  4. for(let i = 0; i < n; i++) {
  5. arr[i] = j;
  6. }
  7.  
  8.  
  9. var currentLength = 1;
  10. var maxLength = 1;
  11. var currentElement = arr[0];
  12.  
  13. for (var index = 0; index < arr.length; index++) {
  14. if (arr[index] === currentElement) {
  15. currentLength +=1;
  16. if (currentLength > maxLength) {
  17. maxLength = currentLength;
  18. }
  19. } else {
  20. currentElement = arr[index];
  21. currentLength = 1;
  22. }
  23. }
  24.  
  25.  
  26.  
  27. print(maxLength);
  28.  
  29.  
  30. print(max);
Advertisement
Add Comment
Please, Sign In to add comment