Choose Three Values with the Largest Product

Quick Overview

Choose Three Values with the Largest Product. Select three distinct array positions in nums and return the largest product of their values.

Choose Three Values with the Largest Product

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Select three distinct array positions in nums and return the largest product of their values. Values may be negative, positive or zero. ```cpp class Solution { public: int maximumProduct(vector<int>& nums); }; ``` ### Examples **Example 1:** ```text nums = [-10,-9,2,3] Output: 270 Explanation: (-10)*(-9)*3 beats the three largest values. ``` **Example 2:** ```text nums = [-5,-4,-2,-1] Output: -8 Explanation: The three values closest to zero give (-4)*(-2)*(-1). ``` ### Constraints - There are 3..10000 input numbers, each in -1000..1000. ### Clarifying Questions Consider two negative factors as well as the three largest values. ```hint Read the boundary condition When can very negative numbers improve a product? ``` ### Contract considerations Consider two negative factors as well as the three largest values.

Overview: Choose Three Values with the Largest Product. Select three distinct array positions in nums and return the largest product of their values.

Google logo
Google
Sep 11, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Select three distinct array positions in nums and return the largest product of their values. Values may be negative, positive or zero.

class Solution {
public:
    int maximumProduct(vector<int>& nums);
};

Examples

Example 1:

nums = [-10,-9,2,3]
Output: 270
Explanation: (-10)*(-9)*3 beats the three largest values.

Example 2:

nums = [-5,-4,-2,-1]
Output: -8
Explanation: The three values closest to zero give (-4)*(-2)*(-1).

Constraints

  • There are 3..10000 input numbers, each in -1000..1000.

Clarifying Questions Guidance

Consider two negative factors as well as the three largest values.

Contract considerations

Consider two negative factors as well as the three largest values.