convert a number m to n with minimum operations. The operations allowed were -1 and *2.
For Eg : 4 and 6. Answer is 2. 1st operation : -1 -> 4-1 = 3. 2nd operation : * -> 3 * 2 =6.
Here is function to get value of minOperation
int convert(int m, int n) { if (m == n) { return 0; } if (m > n) { return m-n; } if (m <= 0 && n > 0) { return -1; } if (n % 2 == 1) { return 1 + convert(m, n+1); } else { return 1 + convert(m, n/2); } }
Convert the given string into palindrome with minimum number of appends(at end of the given string). O(n) algorithm will be appreciated ??
Input :=> Malayal Output :=> Malayalam
In an "N" element integer sorted array, a particular elements is repeating "(N/2)+1" times. How much time it take to find the repeating element.