Find the most frequent element in an array and optimize your solution for the best possible time complexity.