Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Different Ways to Add Parentheses

XPChallenge Points: 20
levelLevel: Medium

You are given a string expression containing numbers and the operators '+', '-', and '*'.
Your task is to compute all possible results by adding parentheses in different valid ways to change the computation order.
Return all possible outcomes of the expression.
You may return the results in any order.

Example 1:

Input: expression = "3-2-1"

Output: [0, 2]

Example 2:

Input: expression = "2*3+4*2"

Output: [20, 16, 28, 14, 20]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result