Dsa
Bit Manipulation
Medium
Forbidden Bit-Hops
Given two integers 'Start' and 'End' (both between 0 and 1023) and a list of 'Forbidden' integers, find the minimum number of steps to reach 'End' starting from 'Start'. In each step, you can flip exactly one bit of the current number's 10-bit binary representation. You cannot step on any integer that is in the 'Forbidden' list.
Input Format:
Two space-separated integers, Start and End.
A space-separated list of Forbidden integers.
Output Format:
A single integer representing the minimum steps, or -1 if unreachable.
Example:
Input:
0 7
1 2 4
Output:
-1
(Explanation: To reach 7 (111) from 0 (000), you must flip bits which results in 1, 2, or 4. Since all are forbidden, no path exists.)
Key concepts
bit_manipulationbfsgraph_theory
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