Ad
  • Custom User Avatar

    Hence it's very slow. sorted + arr.count applied to every element of array.

  • Custom User Avatar

    I think it goes like this: key=arr.count applies this to each element of array, so as it goes through sorted array its value will be 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 on each element (arr.count(12) == 2 and so on...), so max() returns first element that has the highest count, which in sorted array is 7. Docs state that: "If multiple items are maximal, the function returns the first one encountered." For example, if array was not sorted and switched 6 and 7, like [12, 12, 10, 10, 10, 6, 6 ,6 ,6, 7, 7, 7, 7] then it would return 6, since its the first element with highest count. Hope this clears it up.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution