Posts

Showing posts with the label dynamic-programming

Minimum pluses required to make the equation (x = y) correct

4 1 Problem Statement : Given an equation “x=y”, for example, “111=12”, you need to add pluses inside x to make the equation correct. In our example “111=12”, we can add one plus “11+1=12” and the equation becomes correct. You need to find the minimum number of pluses to add to x to make the equation correct. If there is no answer print -1. Note that the value of y won’t exceed 5000. The numbers in the corrected equation may contain arbitrary amounts of leading zeros. Input Format The first line contains a string, A as described in the problem statement. Constraints 1 <= len(A) <= 10^3 I tried the recursive approach. Which is for every character in the 'x', I have two options I can include the plus sign next to the current digit or move to the next ...