🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: How Hashing Works: all 13 questions

Quiz: How Hashing Works · Question 9 of 13

What does this print? (code)

What does this print?

def bucket(key, size):
    return sum(ord(ch) for ch in key) % size

print(bucket("ab", 7), bucket("ba", 7), bucket("abc", 7))
  1. A.0 1 2
  2. B.6 0 0
  3. C.6 6 0
  4. D.1 1 6
Answer & explanation

Correct answer: 6 6 0

"ab" and "ba" have the same letter sum (195), so they collide in bucket 6; "abc" sums to 294, which is 0 mod 7.

Can you get the rest right without peeking?

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

Start the quiz →