PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Schedule Priority Jobs with Cooldowns

Last updated: Jul 28, 2026

Quick Overview

Implement a recurring-job scheduler that selects the highest-priority eligible job and enforces cooldowns measured in later retrieval calls. Preserve insertion-order tie-breaking while handling empty calls, zero cooldowns, duplicate IDs, large workloads, concurrent workers, updates, and removals.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Schedule Priority Jobs with Cooldowns

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

# Schedule Priority Jobs with Cooldowns Implement a scheduler for recurring jobs: ```text addJob(job_id, priority, cooldown) -> bool getJob() -> job_id or None ``` `addJob` inserts a new job and returns `false` if the ID already exists. Every successful `getJob` call selects the eligible job with the greatest priority; ties are broken by earlier insertion. The selected job remains registered but becomes ineligible for its configured number of subsequent `getJob` invocations. Calls that return `None` still count toward cooldown progress. For example, a job with cooldown `3` selected on call 5 cannot be selected on calls 6, 7, or 8 and becomes eligible on call 9. A cooldown of `0` permits selection on the next call. ## Constraints - Up to `200000` total operations. - Priorities and cooldowns are non-negative integers. - Job IDs are unique non-empty strings. - Avoid scanning every registered job on each call. ## Example Add `A` with priority 10 and cooldown 2, then `B` with priority 5 and cooldown 0. Four calls to `getJob` return `A, B, B, A`. ## Clarifications Insertion order never changes after a job runs. Define the invocation counter precisely and explain how jobs move between waiting and eligible structures. ## Hints One priority structure can hold eligible jobs while another structure orders cooling jobs by the invocation when they become eligible. ## Extensions - Support priority updates and job removal. - Use wall-clock release times instead of invocation counts. - Make `getJob` safe for concurrent workers without returning one job twice.

Quick Answer: Implement a recurring-job scheduler that selects the highest-priority eligible job and enforces cooldowns measured in later retrieval calls. Preserve insertion-order tie-breaking while handling empty calls, zero cooldowns, duplicate IDs, large workloads, concurrent workers, updates, and removals.

Related Interview Questions

  • Implement Multi-Player Tic-Tac-Toe - Amazon (medium)
  • Find Paths Across a Weighted Binary Grid - Amazon (medium)
  • Compute Edit Distance - Amazon (medium)
  • Minimize Replacements So Equal Product Values Are Contiguous - Amazon (hard)
|Home/Coding & Algorithms/Amazon

Schedule Priority Jobs with Cooldowns

Amazon logo
Amazon
Jul 17, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

Schedule Priority Jobs with Cooldowns

Implement a scheduler for recurring jobs:

addJob(job_id, priority, cooldown) -> bool
getJob() -> job_id or None

addJob inserts a new job and returns false if the ID already exists. Every successful getJob call selects the eligible job with the greatest priority; ties are broken by earlier insertion. The selected job remains registered but becomes ineligible for its configured number of subsequent getJob invocations. Calls that return None still count toward cooldown progress.

For example, a job with cooldown 3 selected on call 5 cannot be selected on calls 6, 7, or 8 and becomes eligible on call 9. A cooldown of 0 permits selection on the next call.

Constraints

  • Up to 200000 total operations.
  • Priorities and cooldowns are non-negative integers.
  • Job IDs are unique non-empty strings.
  • Avoid scanning every registered job on each call.

Example

Add A with priority 10 and cooldown 2, then B with priority 5 and cooldown 0. Four calls to getJob return A, B, B, A.

Clarifications

Insertion order never changes after a job runs. Define the invocation counter precisely and explain how jobs move between waiting and eligible structures.

Hints

One priority structure can hold eligible jobs while another structure orders cooling jobs by the invocation when they become eligible.

Extensions

  • Support priority updates and job removal.
  • Use wall-clock release times instead of invocation counts.
  • Make getJob safe for concurrent workers without returning one job twice.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.