5.7 ➕➖ Elementary math gone wrong ❌➗
Gauresh, tired of the endless grind of engineering assignments, decided to take a break. Looking for something light, he stumbled across his 6th-grade math problems that seemed doable. The task was simple—or so he thought, Given a sequence of digits, he had to insert operators like +, -, *, and / between the digits to make the expression equal a target number.
Now, he is determined to figure out all the valid ways to insert the operators and reach the target—turning this elementary math sheet into his latest headache.
Constraints
1 <= num.length <= 10
num consists of only digits.
0 <= target value <= 231
Input Format
first line contains a string of numbers[num] ,suppose nums =100, here (100),(1,0,0 ),(1,00) and (10,0) are all posible operand combinations.
Second line contains target value of expression
Output Format
The word "Expressions:" followed by set of all possible expressions each on newline(maybe none) ,note that there are be multiple possible expressions, you have to output them in such an order that is produced by considering + - * and / operators in order, specific to the example.
Example 1
Input:
100
1
Output:
Expressions:
1+0+0
1+0-0
1+0*0
1-0+0
1-0-0
1-0*0
Explanation:
All expressions evaluate to 1, note the order in which expressions are outputted, it must be preserved.
Log In to solve the Question