The problem. Given a string expression of numbers and the operators +, - and *, return all the results you can get by adding parentheses in every possible way. The answers can be in any order, with repeats.
expression = "2-1-1" -> [0, 2] ((2-1)-1 = 0, 2-(1-1) = 2)
expression = "2*3-4*5" -> [-34, -14, -10, -10, 10]
expression = "11" -> [11]Members only · free account
The rest of this lesson, with 6 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson