Back to course sections
    Mark As Completed Discussion

    Good morning! Here's our prompt for today.

    Given an unsorted array of integers, can you write a method maxProductOfThree(unsorted: array) to find the largest product from three of the numbers? For example, given the following array:

    [-1, 9, 22, 3, -15, -7]

    The largest product of three numbers is 2310. This results from -15 * -7 * 22.

    Description

    Constraints

    • Length of the array <= 100000
    • The array will contain values between -1000 and 1000
    • The final answer would always fit in the integer range
    • Expected time complexity : O(n * log n)
    • Expected space complexity : O(1)

    Try to solve this here or in Interactive Mode.

    How do I practice this challenge?

    JAVASCRIPT
    OUTPUT
    :001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

    Tired of reading? Watch this video explanation!

    To change the speed of the video or see it in full screen, click the icons to the right of the progress bar.

    Here's our guided, illustrated walk-through.

    How do I use this guide?

    Access all course materials today

    The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.

    Returning members can login to stop seeing this.