Priority job batch

Write codeEasy17 min

Your task

A batch runner holds every submitted job in one queue and drains part of it during each nightly maintenance window. job_names lists the jobs in the order they were submitted, and priorities[i] is the priority the operator gave job_names[i]. A larger priority starts sooner, and a priority may be negative for work that is content to wait. When two jobs carry the same priority, the one submitted earlier, meaning the smaller index, starts first, so the running order is fully determined. Tonight the window has room for slots jobs. Return the names of the jobs the runner starts, in the order it starts them. Return every job in running order when slots is larger than the queue, and an empty list when slots is zero or negative. Job names are not guaranteed to be unique.

Examples

scheduler_first_jobs(job_names: list[str], priorities: list[int], slots: int) -> list[str]
Example 1
Inputscheduler_first_jobs(["reindex", "backup", "email"], [2, 5, 2], 2)
Output["backup", "reindex"]
Example 2
Inputscheduler_first_jobs(["alpha", "beta", "gamma"], [1, 1, 1], 5)
Output["alpha", "beta", "gamma"]
Example 3
Inputscheduler_first_jobs(["nightly", "hotfix"], [0, -3], 1)
Output["nightly"]