🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Graph Theory Workshop: all 14 questions

Quiz: Graph Theory Workshop · Question 11 of 14

What does this print? (code)

What does this print?

def havel_hakimi(seq):
    seq = sorted(seq, reverse=True)
    while seq and seq[0] > 0:
        d = seq.pop(0)
        if d > len(seq):
            return False
        for i in range(d):
            seq[i] -= 1
            if seq[i] < 0:
                return False
        seq.sort(reverse=True)
    return True
print(havel_hakimi([3, 3, 2, 2, 2]), havel_hakimi([3, 3, 3, 1]))
  1. A.True True
  2. B.True False
  3. C.False True
  4. D.False False
Answer & explanation

Correct answer: True False

3 3 2 2 2 reduces to all zeros, while 3 3 3 1 gets stuck, exactly as in the lesson.

Can you get the rest right without peeking?

Take the timed Quiz: Graph Theory Workshop quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →