Problem 138273 · easy · Phase 01 Prerequisites & Setup

Join the Queue at a Position

lists · insert · copying

A queue of customers is stored as a list of names. Write insert_at(queue, index, name) that returns a new list in which name has been placed at position index, pushing later customers back by one. If index is larger than or equal to the length of the queue, the name goes at the very end. The original list must not be modified.

Examples

Input:  queue = ["ana", "bo", "cy"], index = 1, name = "dee"
Output: ["ana", "dee", "bo", "cy"]

Input:  queue = ["ana", "bo"], index = 5, name = "eve"
Output: ["ana", "bo", "eve"]

Constraints

  • 0 <= len(queue) <= 5000
  • 0 <= index <= 10000

Goals

  • Copy a list so the original is untouched
  • Use insert to place an item at a given index
Starting Python…