For a given string of binary number bi. Find the two’s complement of it.
Input: bi = 00000101
Explaination: 2's complement is reversing all
the bits of the given number and then adding
1 to it.
Input: bi = 101
Explaination: Follow the process of figuring
out 2's complement. This will be the answer.
You do not need to read input or print anything. Your task is to complete the function complement() which takes bi as input parameter and returns the 2's complement of the number.
Expected Time Complexity: O(|bi|)
Expected Auxiliary Space: O(|bi|)
1 ≤ |bi| ≤ 10
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
want to view the editorial?
Login to access your submissions.