🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: File Organization and Hashing: all 9 questions

Quiz: File Organization and Hashing · Question 3 of 9

What does this print? (code)

What does this print?

M = 5
buckets = [[] for _ in range(M)]
for k in [10, 21, 35, 7, 12, 40]:
    buckets[k % M].append(k)
print([len(b) for b in buckets])
  1. A.[1, 1, 1, 1, 2]
  2. B.[3, 1, 2, 0, 0]
  3. C.[2, 1, 2, 1, 0]
  4. D.[3, 1, 1, 1, 0]
Answer & explanation

Correct answer: [3, 1, 2, 0, 0]

10, 35 and 40 go to bucket 0; 21 to 1; 7 and 12 to 2.

Can you get the rest right without peeking?

Take the timed Quiz: File Organization and Hashing quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →