id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

rnewton31@gatech.edu > deli_counter_mixup
prev  |  next  |  chance

Uh oh! The queue for the deli counter has gotten out of order! Some people stepped out of line, and now they need to know where in line they should be. Thankfully, everyone has a ticket, so they'll be able to find their spot again. Given a list, queue, containing the ticket numbers of everyone in the queue and a second list, tickets, containing the ticket numbers of everyone who has stepped out of line, return a list of indices into queue where each ticket in tickets should be inserted in order to preserve the queue order.

For example, if queue = [1, 3], and tickets = [2, 4], ticket number 2 needs to be inserted at queue index 1 (right before ticket number 3 in the queue), and ticket number 4 needs to be inserted after ticket number 3, so it needs to be inserted at index 2. Specifically, for a given ticket in tickets, if the ticket at queue index i is less than the ticket in question but the ticket at queue index i + 1 is greater than the ticket (or if i + 1 == len(queue)), the ticket in question should be inserted at index i + 1. If i == 0 but queue[i] is less than the ticket in question, the ticket should be inserted at queue index 0.

queue will always be sorted, but tickets might not be. No two tickets in tickets will be inserted at the same index in queue.

This will require a double-nested for loop. One to loop over the tickets in tickets and another to loop over indices used to access queue.


deli_counter_mixup([1, 3], [2]) → [1]
deli_counter_mixup([1, 3], [2, 4]) → [1, 2]
deli_counter_mixup([1, 3, 4, 6], [2, 5]) → [1, 3]

...Save, Compile, Run (ctrl-enter)

def deli_counter_mixup(queue, tickets):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 299

Copyright Nick Parlante 2017 - privacy