Guest User

Untitled

a guest
Jun 9th, 2021
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let input = ["13", "4,1,1,4,2,3,4,4,1,2,4,9,3"];
  2.  
  3. let gets =this.gets ||( (arr, index) => () => arr[index++])(input, 0);
  4. let print = this.print || console.log;
  5.  
  6. let n = +gets();
  7. let arr = gets().split(",").map(Number);
  8.  
  9. let hash = new Map();
  10. for (var i = 0; i < n; i++) {
  11. if (hash.has(arr[i])) {
  12. hash.set(arr[i], hash.get(arr[i]) + 1);
  13. } else {
  14. hash.set(arr[i], 1);
  15. }
  16. }
  17.  
  18. let repeatedTimes = 0;
  19. let repeatingNumber = -1;
  20. hash.forEach((value, key) => {
  21. if (repeatedTimes < value) {
  22. repeatingNumber = key;
  23. repeatedTimes = value;
  24. }
  25. });
  26.  
  27. print(`${repeatingNumber} (${repeatedTimes} times)`);
RAW Paste Data