L&T Mindtree · Question 73
Reverse Bits
Problem
You are given 32-bit unsigned integer. Reverse its bits.
Approach
Shift bits from n into the result, LSB first, 32 times.
Time O(1)Space O(1)
How it works
- 1Pull the lowest bit of n into the result's bottom.
- 2Shift result left and n right (unsigned), 32 rounds.
Sample input / output
Input: n = 11111111111111111111111111111101 (i.e. -3 as int) Output: -1073741825
Constraints
32-bit unsigned semantics; Java int uses >>> for logical shift.
Solution — read it, then walk it
Time O(1)Space O(1)Loops 1Returns 1source · Java
Scroll sideways for wide charts — the view follows the active step.
- start / end
- statement
- condition
- loop
- returns
- definition
1/12
StartSTART
Interactive control-flow diagram and step-by-step code walkthrough.
Recommended resourcesAffiliate links · may earn us a commission
Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits