Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Process each bit position of a, b, and c from least significant to most significant. If c's bit is 0, both a and b bits must be 0, so count flips for any 1s. If c's bit is 1, at least one of a or b must be 1, so add a flip only if both are 0.
Analyzing each bit independently reduces the problem to per-bit logic: a target 0-bit requires clearing both inputs (up to 2 flips), while a target 1-bit requires at most one flip if neither input contributes.
Updated Feb 2026