40/40
Part 8 of 8 · Follow-upsCheck yourself
Check yourself
6 questions
  1. 1.A heap holds n items. What does it cost to look at the smallest, to pop it, and to push a new item?

  2. 2.After heapq.heapify(h), h is [7, 12, 18, 30, 21, 45, 60]. Which gives the four smallest items?

  3. 3.You push (expires, credit) onto a heap, where each credit is a dict, and two credits expire at 30. What happens?

  4. 4.To keep the 3 closest points, you push (dist, point) onto a heap and pop whenever it holds 4. Which 3 points does it keep?

  5. 5.Each meeting holds a room for start <= t < end. Before placing a meeting that starts at start, which line frees the rooms that are done?

  6. 6.Your heap of [expires, count, credit_id, left] entries holds a credit that was cancelled. What should you do?

Now the problem this lesson builds to: 22 A GPU credit ledger with expiring creditsPractice it