Description

In the four fundamental arithmetic operations, associative law is valid for plus (+) but not for minus (-).
For example, the expression 1 - 5 - 3 produces different results according to the following calculations.

  • ((1 - 5) - 3) = -7
  • (1 - (5 - 3)) = -1

As another example, the expression 1 - 3 + 5 - 8 produces 5 different results.

  • (((1 - 3) + 5) - 8) = -5
  • ((1 - (3 + 5)) - 8) = -15
  • (1 - ((3 + 5) - 8)) = 1
  • (1 - (3 + (5 - 8))) = 1
  • ((1 - 3) + (5 - 8)) = -5

As shown above, the results of different calculation order are [-15, -5, -5, 1, 1], where the maximum value is 1.
Given an array arr containing numbers in string format, plus symbol (+), and minus symbol (-) as parameters, write a function solution to return the maximum value among results of different calculation order.

Constraints
  • arr is an array containing two operators, "+" and "-", and numbers. Its length is between 3 and 201.
    • The length of arr is always odd value.
    • arr has more than 2 and less than 101 numbers. The number of operators is (the number of digits) -1.
    • The numbers in arr are between 1 and 1,000 and in string format (ex: 456).
  • The first and last elements of array are always numbers, and number and operator always appear alternately.

Examples
arr result
["1", "-", "3", "+", "5", "-", "8"] 1
["5", "-", "3", "+", "1", "+", "2", "-", "4"] 3

Example #1
As shown in above example, (1-(3+(5-8))) = 1.

Example #2
(5-(3+((1+2)-4))) = 3.

Result Stop
Result of [Run] or [Submit] will be displayed here