Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const jury = +gets();
  2. const votes = Array.from({
  3.     length: jury
  4. }).map(() => +gets()).sort((a, b) => (a - b));
  5.  
  6. let currentSum = 1;
  7. let maxSum = 0;
  8. let mostCommon;
  9.  
  10. for (let i = 0; i < votes.length; i++) {
  11.     if (votes[i] === votes[i + 1]) {
  12.         currentSum += 1;
  13.     } else {
  14.         currentSum = 1;
  15.     }
  16.     if (maxSum < currentSum) {
  17.         maxSum = currentSum;
  18.         mostCommon = votes[i];
  19.     }
  20. }
  21.  
  22. if (!(maxSum)) {
  23.     print(Math.min(...votes));
  24. } else {
  25.     print(mostCommon);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement