The Blind 75 Leetcode Series: Reverse Bits

Jonathan Chao
5 min readSep 29, 2022
Photo by Chris Ried on Unsplash

Today, we are working on 190. Reverse Bits

Reverse bits of a given 32 bits unsigned integer.

Yep. This is really it. A very short description for the problem. This potentially opens up to a lot of questions for specifications.

We can check if:

  1. When they say “32 bits unsigned integer”, we are given an integer in base-10 and we are supposed to transform it to binary?
  2. The result should also be unsigned?
  3. Do we expect the integer to ever overflow?

First one is important as we want to know what input we are expecting. The first time I read the description for the question, I thought the input is actually already given in binary form.

The reverse of a binary number can result in leading 1, which would indicate a negative number in signed integer. The question gives an unsigned integer but didn’t really specify the output type. This seems redundant, but I’ve seen people who mark this in the interview comment.

We have 32 bits and should only have 32 bits. The input should not be greater than what an int-32 can…

--

--

Jonathan Chao
Jonathan Chao

Written by Jonathan Chao

I am a software developer who has been in this industry for close to a decade. I share my experience to people who are or want to get into the industry

No responses yet