...

Chapter 10 - Python Quest

Queues

Serve the oldest waiting item, rotate turns, manage work limits, and explore in waves.

XP
0Level 1
Stars
0/15quest stars
Combo
0clean runs
Rank
Seed0/160 Python score
Queue front and back

Cafeteria Line

100 XP

The cafeteria has a line of kids already waiting. New arrivals join the back before the helper serves one kid from the front.

Write cafeteria_line(line, arrivals) so it returns [served, remaining]. served is the first kid served, or "nobody" when the queue is empty. remaining is the queue after new arrivals join and one kid is served.

Sample checks

cafeteria_line(["Mia","Sam"], ["Noor"])returns["Mia",["Sam","Noor"]]

Explanation: Noor joins behind Mia and Sam; Mia has waited longest, so Mia is served and Sam then Noor remain

cafeteria_line([], ["Ava","Leo"])returns["Ava",["Leo"]]

Explanation: the line starts empty, Ava arrives before Leo, so Ava reaches the front and Leo remains

Hint

Hints are ready when you want one.

Lesson reference

Review: Add at the back, remove at the front

Your Python

cafeteria_line

Loading editor

Judge

Ready

0/4

Run your code when it feels ready.