From the course: Nail Your Java Interview

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Challenge: Maximum product of two numbers

Challenge: Maximum product of two numbers - Java Tutorial

From the course: Nail Your Java Interview

Start my 1-month free trial

Challenge: Maximum product of two numbers

(upbeat music) - [Instructor] This challenge will test your knowledge of arrays in Java, as well as your algorithm skills. You'll create a function that finds the maximum product of two numbers in an unsorted array. Your function will take one input, an array containing integers, and it will output the maximum product of two integers inside that array. For example, if you are given the following array with five, three, two, five, seven, zero, and one, the maximum product is five times seven, which is 35. Your function would return 35. You could also be given an array with negative numbers. In this case, the maximum product would be negative three times negative eight, which is 24. If you're interested in more technical problems, I suggest you iterate on this challenge. What if you had to return the pair of indices instead of the maximum product? How would your algorithm change? What if I asked for the minimum product?…

Contents