Advertisement
BoGeo

Longest Sequence of Equal - Judge (revised)

Oct 6th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. const getGets = (arr) => {
  2. let index = 0;
  3.  
  4. return () => {
  5. const toReturn = arr[index];
  6. index += 1;
  7. return toReturn;
  8. };
  9. };
  10. // this is the test
  11. const test = [
  12. 12, 5, 2, 3, 4, 5, 5, 5, 5, 6, 7, 6, 7
  13. ];
  14.  
  15.  
  16. const gets = this.gets || getGets(test);
  17. const print = this.print || console.log;
  18.  
  19. // code
  20.  
  21.  
  22. const n = +gets();
  23. const arr = new Array();
  24.  
  25. for(let i = 0; i < n; i++) {
  26. arr.push(gets());
  27. }
  28.  
  29.  
  30. //print(arr);
  31.  
  32. var currentLength = 1;
  33. var maxLength = 1;
  34. var currentElement = arr[0];
  35.  
  36. for (var index = 0; index < arr.length; index++) {
  37. if (arr[index] === currentElement) {
  38. currentLength +=1;
  39. if (currentLength > maxLength) {
  40. maxLength = currentLength;
  41. }
  42. } else {
  43. currentElement = arr[index];
  44. currentLength = 1;
  45. }
  46. }
  47.  
  48.  
  49.  
  50. print(maxLength);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement