🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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=" ")
  1. A.6 8 12 7
  2. B.2 8 4 1
  3. C.1 1 1 1
  4. 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 →