` ````
```

Loading Question ...

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.

**Note:**

- The given integer is guaranteed to fit within the range of a 32-bit signed integer.
- You could assume no leading zero bit in the integer’s binary representation.

**Example 1:**

Input:5Output:2Explanation:The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.

**Example 2:**

Input:1Output:0Explanation:The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.

Seen this question in a real interview before?

Yes

No

When did you encounter this question?

last week

last month

last 3 month

last 6 month

more than 6 months

other

Which stage?

Online Assessment

Phone Interview

On Campus Interview

Onsite Interview

Don't know

Which company?

Adobe

Aetion

Airbnb

Alibaba

Amazon

Apple

Baidu

Bloomberg

Cloudera

Coursera

Cryptic Studios

Dropbox

eBay

Epic Systems

Expedia

Facebook

Fallible

Games

Gilt Groupe

GoDaddy

Goo

Google

Hedvig

Helix

Houzz

Hulu

Indeed

Intuit

IXL

LinkedIn

LiveRamp

Lyft

MAQ Software

Mathworks

Microsoft

NetEase

Netsuite

Palantir

Palantir Technologies

Pinterest

Pocket Gems

Poynt

Pure

Pure Storage

Rackspace

Radius

Riot

Riot Games

Samsung

Snapchat

Square

Storage

Tencent

TinyCo

Twitter

Two Sigma

Uber

Valve

WAP

Works Applications

Yahoo

Yahoo!

Yelp

Zappos

Zenefits

How can we help you?