Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Preloaded Constraints Tasks Class
00:00
5 left

Preloaded Constraints Tasks Class

HardPython

Problem

Coalition Control maintains a preloaded set of security recommendations for each customer. Implement a task manager that always claims the highest-priority active recommendation while supporting additions, priority updates, and cancellations.

Tasks with larger priorities are selected first. When priorities are equal, select the lexicographically smaller task ID. A claim operation removes and returns the selected task. If no active task exists, it returns None.

Formal Specification

Implement run_task_manager(tasks, operations).

  • tasks is a list of unique two-element lists, [task_id, priority], where task_id is a string and priority is an integer.
  • operations is a list of operation lists:
    • ['add', task_id, priority]
    • ['update', task_id, priority]
    • ['cancel', task_id]
    • ['claim']
  • Return a list containing the result of each claim operation, in order. Do not include results for other operations.
  • Inputs follow the validity constraints below.

Constraints

  • 0 <= len(tasks) <= 10^5
  • 1 <= len(operations) <= 2 * 10^5
  • 1 <= len(task_id) <= 40
  • -10^9 <= priority <= 10^9
  • Task IDs are unique among active tasks
  • An update or cancel targets an active task, and add uses an inactive ID
  • The total number of tasks added is at most 10^5

Function Signature

def run_task_manager(tasks, operations):
Interviewer

Your question is Preloaded Constraints Tasks Class. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.