🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Counting Sort and Custom Sorting: all 13 questions

Quiz: Counting Sort and Custom Sorting · Question 9 of 13

What does this print? (code)

What does this print?

nums = [3, 1, 3, 0, 2, 1, 3]
count = [0] * 4
for x in nums:
    count[x] += 1
print(count)
  1. A.[0, 1, 2, 3]
  2. B.[1, 2, 1, 3]
  3. C.[3, 1, 3, 0]
  4. D.[1, 1, 1, 1]
Answer & explanation

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

count[v] is how many times v appears: one 0, two 1s, one 2 and three 3s.

Can you get the rest right without peeking?

Take the timed Quiz: Counting Sort and Custom Sorting quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →