Microsoft VO Coding Interview: Maximum Product of Three Numbers

18 Views
No Comments

Given an array of integers, find the maximum possible product of any three numbers in the array.

The key insight is that the maximum product may come either from the three largest numbers or from the largest number combined with the two smallest numbers, since two negatives can produce a large positive product. A single pass can track the top three maxima and bottom two minima, then compare these two candidate products. This yields an O(n) time, O(1) space solution.

END
 0