Embercode
✕
Greedy AlgorithmsQuick quiz

Hiring and queues in Python

8 questions. Covers Reconstruct a queue by height in Python.

Questions 1 to 5 of 8

  1. 1. In the cheapest-team method, the heap that keeps the K smallest qualities must be a ___ heap, so that its top is the largest quality and that quality can be removed. Type the missing word.

    Type your answer.

  2. 2. For example one (qualities 10, 20 and 5; minimum wages 70, 50 and 30) with K equal to 2, which team is the cheapest?
  3. 3. Put these steps of the cheapest-team method in order. The sort runs once, before the loop. The other three run for each worker, in this order.

    Use the arrows to put the steps in order.

    1. 1.If the heap holds more than K items, pop the top item, which is the largest quality, and take it out of the sum
    2. 2.When the heap holds exactly K workers, compute the current ratio times the sum and keep the smallest cost
    3. 3.Push the worker's negative quality onto the heap and add the quality to the running sum
    4. 4.Sort the workers by minimum wage divided by quality, smallest ratio first
  4. 4. What does this Python code print? ``python line = ['A', 'B'] line.insert(1, 'C') line[0] = 'D' print(line) ``
  5. 5. For example one, worker 0 has ratio 7.0 and quality 10, and worker 2 has quality 5. With K equal to 2, the team is workers 0 and 2 and the shared rate is 7.0. What does worker 2 get paid? Type the number.

    Type your answer.

4 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.