expr made of non-negative integers and the operators +, - and *, with no brackets and no spaces.
Brackets can be placed in many ways, and each full bracketing fixes the order in which the operations run. Evaluate the expression under **every** distinct full bracketing and return all the values you get.
If several bracketings give the same number, it appears in the answer once per bracketing. The values may be returned in any order.expr="6-2+1" → [3, 5]
(6-2)+1 = 5 and 6-(2+1) = 3.
expr="3*4-2*2" → [0, 12, 8, 12, 20]
Five ways to bracket: 3*(4-(2*2)) = 0, 3*((4-2)*2) = 12, (3*4)-(2*2) = 8, (3*(4-2))*2 = 12, ((3*4)-2)*2 = 20. Equal values from different bracketings are repeated.
expr="42" → [42]
+, -, *expr="6-2+1"
[3, 5]
Run checks the first 3 tests in your browser. Submit checks all 113 tests on the server, hidden ones included.