Editor

Customers From One City

#564 · Stacks and queues · Beginner · 35 XP · about 7 min

A delivery company keeps each customer as a list [name, phone, city]. Before a delivery run, a clerk pushes the [name, phone] of every customer in one city onto a stack, then pops the stack until it is empty.

Write pop_customers(customers, city) that does this:

  • Push [name, phone] for every customer whose city is city, in the order they appear in customers. Compare cities ignoring upper and lower case.
  • Pop the stack until it is empty, and return a list of the popped records, followed by the string 'Stack Empty'.

Examples

customers = [
    ['Asha', '98101', 'Goa'],
    ['Ravi', '98202', 'Pune'],
    ['Meera', '98303', 'Goa'],
]
pop_customers(customers, 'Goa')
# returns [['Meera', '98303'], ['Asha', '98101'], 'Stack Empty']
pop_customers(customers, 'Delhi')
# returns ['Stack Empty']

Meera was pushed last, so she is popped first.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.