FunctionRacerProblemsRace

Signs Between the Digits

HardRecursionPython, JavaScript, TypeScript, Java, C++

Between every two neighboring digits of digits you may write +, -, * or nothing; with nothing, the digits join into one longer number. The result is read as usual, with * done before + and -. A number in it may not begin with 0 unless it is 0 itself.

Return every expression whose value is target, in any order.

Example 1

digits "123"
target 6
returns ["1*2*3","1+2+3"]

1 + 2 + 3 and 1 * 2 * 3 are both 6.

Example 2

digits "105"
target 5
returns ["1*0+5","10-5"]

10 - 5 and 1 * 0 + 5 work. 1 * 05 is not allowed, because 05 starts with 0.

Example 3

digits "34"
target 100
returns []

No signs between 3 and 4 reach 100.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems