class Solution:
    def reverseBits(self, n: int) -> int:
        res = 0
        i = 0
        while i < 32:
            res = (res << 1) | (n & 1)
            n >>= 1
            i += 1
        
        return res     

Complexity

Time: since we got to loop through all 32 bits
Space:

Notes

Doesn’t really matter here whether >> does signed right shift since we only care about 32 bits fixed and won’t do any more funny business post that. Output integer varies b/w languages where there is unsigned int type.

Beware of gotchas in langs like JS where the bit shift operators work on 32 bit integers only and returns a 32 bit value, in case question is modified to ask about 64-bit integers