🧩 How do you find the highest product of X items?
This should optimize for runtime complexity and protect from overflows from large products.
- An array of both positive and negative Ints representing potential products to the solution
- An Int representing the number of products required for the solution
- Output: An Int representing the highest product of X amount of numbers.
For example, for the highest product of 3 items, the input is iterated through while updating the following variables. After the iteration has completed in $O(n)$ time, the highest product of three variable is returned as the solution.
- Lowest number
- Highest number
- Lowest product of two
- Highest product of two
- Highest product of three