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 highest number.
Here's an example:
1 * (2 + 3) = 5
1 * 2 * 3 = 6
1 + 2 * 3 = 7
(1 + 2) * 3 = 9 <-- So the maximum value that you can obtain is 9.
Tests
expression_matter(5, 1, 3)
expression_matter(3, 5, 7)
expression_matter(5, 6, 1)
expression_matter(1, 6, 1)
expression_matter(2, 6, 1)
Good luck!
This challenge comes from MrZizoScream on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (7)
If one of the numbers is 1, and if the next bigger number is y and largest number is z, ans will be z * (1 + y), else ans will be x * y * z
So
Here is a Python solution,
Output,
Here is the simple solution for PHP:
maybe not the most elegant, but it work!
My solution using Rust .
Playground
In javascript
Hmm yes, but looking at the examplea given, I assumed a, b and c would be positive