Three Highest Numbers
Given an array, return the 3 max numbers in linear time, and constant space.
The Idea: Find the max 3 times. Every time, modify the contents of the array so that previous maximum is ignored. Restore the contents of the array in the end.
Complexity: O(n) time and O(1) space
Last updated