Challenge - 5 Problems
Bit Manipulation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Bitwise AND vs Arithmetic AND
What is the output of the following Go code snippet?
DSA Go
package main import "fmt" func main() { a := 12 // binary: 1100 b := 10 // binary: 1010 fmt.Println(a & b) }
Attempts:
2 left
💡 Hint
Bitwise AND compares bits of two numbers and returns 1 only if both bits are 1.
✗ Incorrect
The bitwise AND of 12 (1100) and 10 (1010) is 8 (1000 in binary).
❓ Predict Output
intermediateOutput of Left Shift vs Multiplication
What is the output of this Go code snippet?
DSA Go
package main import "fmt" func main() { x := 7 y := x << 2 fmt.Println(y) }
Attempts:
2 left
💡 Hint
Left shift by 2 bits multiplies the number by 4.
✗ Incorrect
Shifting 7 left by 2 bits equals 7 * 4 = 28.
🔧 Debug
advancedWhy Does This Bitwise XOR Code Fail?
What error or output does this Go code produce?
DSA Go
package main import "fmt" func main() { var a int = 15 var b int = 7 fmt.Println(a ^ b) fmt.Println(a ^^ b) }
Attempts:
2 left
💡 Hint
Check the operator symbols carefully.
✗ Incorrect
The first print outputs 8 (bitwise XOR of 15 and 7). The second print uses ^^ which is invalid syntax in Go, causing a compile error.
🧠 Conceptual
advancedWhen Does Bit Manipulation Beat Arithmetic?
Which scenario best explains when bit manipulation is faster than arithmetic operations?
Attempts:
2 left
💡 Hint
Bit shifts can replace multiplication or division by 2, 4, 8, etc.
✗ Incorrect
Bit manipulation is faster for multiplying or dividing by powers of two because shifting bits is simpler than arithmetic operations.
🚀 Application
expertFind the Single Number Using Bit Manipulation
Given an array where every element appears twice except one, which bit manipulation operation helps find the single element efficiently?
Attempts:
2 left
💡 Hint
XOR of a number with itself is zero.
✗ Incorrect
XORing all elements cancels out duplicates because x ^ x = 0, leaving the unique element.
