← Quiz: Segment Tree and Fenwick Tree: all 10 questions
Quiz: Segment Tree and Fenwick Tree · Question 6 of 10
What does this print? (code)
What does this print?
for i in [6, 8, 12, 7]:
print(i & -i, end=" ")
- A.6 8 12 7
- B.2 8 4 1
- C.1 1 1 1
- D.2 4 4 1
Answer & explanation
Correct answer: 2 8 4 1
i & −i keeps only the lowest set bit: 110 → 10, 1000 → 1000, 1100 → 100, 111 → 1.
Can you get the rest right without peeking?
Take the timed Quiz: Segment Tree and Fenwick Tree quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →