The Blind 75 Leetcode Series: Reverse Bits
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:
- When they say “32 bits unsigned integer”, we are given an integer in base-10 and we are supposed to transform it to binary?
- The result should also be unsigned?
- 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…