Coders Crushby Napplied AI
Back to DSA Problems
EasyBit Manipulation

Reverse Bits

Reverse bits of integer

Solution Approach

Extract LSB from n, append to result by left shift. Process 32 times for 32-bit integer.

Implementation
def reverseBits(n):
    result = 0
    for i in range(32):
        result = (result << 1) | (n & 1)
        n >>= 1
    return result
Complexity Analysis

Time Complexity

O(1)

Space Complexity

O(1)
Complexity
Time:O(1)
Space:O(1)
Asked at
MicrosoftAmazon
Coders Crushby Napplied AI

The ultimate interview preparation platform. Master System Design, DSA, and tackle community challenges to crush your FAANG interviews.

Looking for jobs? Visit Napplied AI Jobs Search Agent

System Design

  • All Problems
  • Easy
  • Hard

DSA

  • All Problems
  • Dynamic Programming
  • Graphs

More

  • Problems Arena
  • Growth Paths
  • My Crush

Coders Crush by Napplied AI - Tech Interview & Coding Should Be Effortless