Ad
  • Default User Avatar

    Counter(arr).items() returns a list of [(key1, value1), (key2, value2), ...] where the keys are the distinct numbers in arr and the values are the occurrences of that key in arr. You can pass this into the max function with a custom key to retrieve the max value. The key takes in a (key, value) instance and compares it against other elements by first comparing x[1] then x[0] where x[1] is the occurrence of that number and x[0] is the number as stated before. You need to apply [0] to the outputted (key,value) of the max function to obtain the distinct number.

  • Custom User Avatar

    normally efficiency. But here, it's done in a pretty stupid way, which makes this solution even slower than the O(n²) solution without the set... XD

    => See the fork.