Hard · Backtracking

Expression Add Operators

Given a string num of digits and an integer target, return every expression made by putting '+', '-' or '*' (or nothing, which joins digits into one operand) between the digits that evaluates to target with the usual precedence; no operand may have a leading zero. Return them in any order.

Examples

Example 1

{
  "num": "123",
  "target": 6
}

Output: 2 found

Example 2

{
  "num": "232",
  "target": 8
}

Output: 2 found

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Backtracking problems