I solved it in O(n^2). Got TLE for 3/15 Test cases. Stuck with optimization.Do comment if you guys have any optimised approaches
I used the following logic, but only partial test cases were passed. Do comment if you have alternate approaches
case 1: string length is even
If number of ones in the string is not even, return -1. Else, return numberOfOnes/2
case 2: string length is odd
If difference between number of ones before mid character and after mid character is even, return differenceInOnes/2.
Else, return (differenceInOnes/2)+1 (Note: You can always make a odd lengthed string palindrome by moving the extra one to middle)
I don't know what went wrong with my logic on problem 2.
Totally disappointed with my performance. Will strive hard and do well next time. Please post if you guys have any optimised/efficient solutions
Thanks