Generate Max Value Expression

57 Views Asked by At

How to insert * AND + OPERATORS between a given set of integers so that the expression evaluates to the max possible value

if Set is [3,4,5,6,-2] it should give 3*4*5*6+-2 and also note that * gets precedence over + while evaluating

Saw this in a blog, but could not come up with an answer other than doing a brute force exhaustive search

Transferred from Stack Overflow