Z50

Expression Add Operators

Staff / Principal Engineer
Target Time: 40 - 50 Minutes
Type: ARRAY

Problem Statement & Objective

Given a string num that contains only digits and an integer target, return all possibilities to insert binary operators '+', '-', and/or '*' between the digits of num so that the resultant expression evaluates to target.

Function Signature (Python)

expression_add_operators(nums: str, target: int) -> list[str]

Input & Output Contract

Output Rule:Geçerli matematiksel ifadelerin listesi.

System Constraints

1 <= sayilar.length <= 10
-2^31 <= hedef <= 2^31 - 1

Example Execution Walkthrough

sayilar = '123', hedef = 6 -> ['1*2*3', '1+2+3']
sayilar = '232', hedef = 8 -> ['2*3+2', '2+3*2']

Example Test Scenarios (3)

Example 1
Input:["123",6]
Expected Output:["1*2*3","1+2+3"]
Example 2
Input:["232",8]
Expected Output:["2*3+2","2+3*2"]
Example 3: Çözüm Yok
Input:["3456237490",9191]
Expected Output:[]
Loading Python Editor...
Input Parameters
[
  "123",
  6
]
Expected Output
[
  "1*2*3",
  "1+2+3"
]