Maximum Product of Three Numbers
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given an integer array nums with at least three elements, choose three elements at distinct indices so that their product is as large as possible, and return that product.
Values can be negative or zero, so the best triple is not always the three largest numbers: two large-magnitude negatives multiplied by the largest positive can win.
Aim for O(n) time (a sort-based O(n log n) solution is also acceptable).
Examples
Constraints
- 3 <= nums.length <= 10^4
- -1000 <= nums[i] <= 1000
- The answer fits in a 32-bit signed integer.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.