Signs Between the Digits
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
1 <= len(digits) <= 7digitsholds digits0to9-106 <= target <= 106
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Recursion problems
- Spell It With TilesHard
- Swap the Balanced PiecesHard
- Times Before PlusHard
- Valleys in the Folded StripHard
- Count the BoxesBeginner
- Digit TallyBeginner
- Equal NeighboursBeginner
- Halving TotalBeginner