# Thread: Greedy Algo Problem - Find a highest product

1. Beginner
Join Date
Jun 2018
Posts
3
Qt products
Platforms

## Greedy Algo Problem - Find a highest product

Hi,

I'm trying to solve greedy algo problem listed here. Can you guys drop some hints on how can I solve this?

Problem -

Given an array of integers, return the highest product possible by multiplying 3 numbers from the array

Qt Code:
`array of integers e.g {1, 2, 3}`
To copy to clipboard, switch view to plain text mode

Example:

Qt Code:
`[0, -1, 3, 100, 70, 50] => 70*50*100 = 350000`
To copy to clipboard, switch view to plain text mode

Join Date
Jul 2008
Location
Germany
Posts
464
Thanks
10
Thanked 61 Times in 59 Posts
Qt products
Platforms

## Re: Greedy Algo Problem - Find a highest product

Hi, simple but probably not fast solution:
std::sort on the array, then multiply last three elements.

Ginsengelf

3. ## The following user says thank you to Ginsengelf for this useful post:

d_stranz (21st June 2018)

4. ## Re: Greedy Algo Problem - Find a highest product

Very clever. Certainly much faster than a combinatorial method, even with the sorting.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.