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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Backtracking problems