Given three integers a ,b ,c, return the largest number obtained after inserting the following operators and brackets: +, *, ()
In other words , try every combination of a,b,c with [*+()] , and return the Maximum Obtained
Consider an Example :
With the numbers are 1, 2 and 3 , here are some ways of placing signs and brackets:
1 * (2 + 3) = 51 * 2 * 3 = 61 + 2 * 3 = 7(1 + 2) * 3 = 9
So the maximum value that you can obtain is 9.
def expression_matter(a, b, c):
return max(a + b + c, (a + b) * c, a * (b + c), a * b * c)
print(expression_matter(1,2,3))
Training on Expressions Matter | Codewars
No comments :
Post a Comment