🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Routing Algorithms: all 10 questions

Quiz: Routing Algorithms · Question 9 of 10

What does this print? (code)

What does this print?

cost = {"Y": 3, "Z": 1}
their = {"Y": 2, "Z": 6}
best = min(cost, key=lambda v: cost[v] + their[v])
print(best, cost[best] + their[best])
  1. A.Z 7
  2. B.Z 1
  3. C.Y 5
  4. D.Y 2
Answer & explanation

Correct answer: Y 5

Y gives 3 + 2 = 5 and Z gives 1 + 6 = 7, so Y wins with 5.

Can you get the rest right without peeking?

Take the timed Quiz: Routing Algorithms quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →