Dsa
Bit Manipulation
Easy
The Cyclic Shift Recovery
A 32-bit unsigned integer A has been cyclically shifted to the right some number of positions (0 to 31) to become integer B. Given A and B, determine the minimum number of right cyclic shifts required to transform A into B. If B cannot be reached from A via cyclic shifts, output -1.
Input Format:
Two space-separated 32-bit unsigned integers, A and B.
Output Format:
A single integer representing the shift count or -1.
Example:
Input:
1610612736 3
Output:
29
Explanation:
1610612736 is 01100000 00000000 00000000 00000000 in 32-bit binary.
Shifting it right by 29 positions results in 00000000 00000000 00000000 00000011, which is 3.
Key concepts
bit_manipulationcircular_shift
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now