Given an equation x==y for ex 111=12, you need to add pluses inside x to make the equation correct. In our example “111=12” we can add a plus like this → “11+1=12” & 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 then print -1.
Input : A string
s which is the equation
The value of y does not exceed
There is a unique ATM in wonderland. Imagine this ATM as array of numbers. You can withdraw cash only from either ends of the array. Sarah wants to withdraw X amount of cash from the ATM. What are the minimum number of withdrawals Sarah would need to accumulate X amount of cash . If not possible print -1.
I have an
O(n^2) approach for 2nd ques i guess, but is there any better way.
P.S These questions are from Infosys sample test for HackwithInfy and not from ongoing contest…