2's Complement
Basic Accuracy: 53.66% Submissions: 239 Points: 1

For a given string of binary number bi. Find the two’s complement of it.

Example 1:

Input: bi = 00000101
Output: 11111011
Explaination: 2's complement is reversing all 
the bits of the given number and then adding 
1 to it.

Example 2:

Input: bi = 101
Output: 011
Explaination: Follow the process of figuring 
out 2's complement. This will be the answer.

Your Task:
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 are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

2's Complement

Output Window