Expression Add Operators Problem
Expression Add Operators Problem — ExecCode Medium DSA Practice
Solve the Expression Add Operators problem on ExecCode. Free online medium DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.
Problem description
You are given a numeric string. Insert binary operators +, -, * between digits (or insert nothing to glue digits into a larger number) so the expression equals target. No unary minus, no leading zeros on a number (except the number 0 itself). Return every valid expression string, sorted. Return a sorted list of expression strings. Empty list if none. You are given: num — digits target — integer target Return sorted list of strings. Do not use exponent or division.
Examples
Input {'num': '123', 'target': 6}; Output ['123', '1+2+3']. Input {'num': '232', 'target': 8}; Output ['23+2', '2+32']. Input {'num': '105', 'target': 5}; Output ['1*0+5', '10-5']
Constraints
Multiplication binds tighter than +/ You evaluate left to right except that * binds to the previous operand
Practice Expression Add Operators free on ExecCode. Browse DSA problems, topic map, and placement guides.