Find the most frequently occurring item in an array. Example: The most frequently occurring item in
[1, 3, 1, 3, 2, 1]
is1
. If you're given an empty array, you should returnnull
(in Java) orNone
(in Python). You can assume that there is always a single, unique value that appears most frequently unless the array is empty. For instance, you won't be given an array such as[1, 1, 2, 2]
. NOTE: Use lists instead of arrays in Python for simplicity.
I've written an implementation that determines the solution in linear time complexity (O(n)
).
Languages Implemented: