Given a binary representation in the form of string(S) of a number n, the task is to find a binary representation of n+1.
Input: S = "10" Output: 11 Explanation: "10" is the binary representation of 2 and binary representation of 3 is "11"
Input: S = "111" Output: 1000 Explanation: "111" is the binary representation of 7 and binary representation of 8 is "1000"
You don't need to read input or print anything. Complete the function binaryNextNumber()which takes S as input parameter and returns the string.
Expected Time Complexity:O(N)
Expected Auxiliary Space: O(N) to store resultant string
1 <= N <= 104
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes