Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Sort Tasks by Priority and Time

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Sort Tasks by Priority and Time. Start with the requirements on the right.

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.

Problem

Claude Code receives a collection of tasks that must be presented in execution order. Sort the tasks by higher priority first. When two tasks have the same priority, place the task with the smaller creation_order first so older tasks are processed before newer ones.

Return a new list containing the original task dictionaries in the required order. Do not modify the input list.

Formal Specification

Implement sort_tasks(tasks), where tasks is a list of dictionaries. Each dictionary contains:

  • id: a unique string identifying the task
  • priority: an integer from 1 through 10, where 10 is highest priority
  • creation_order: a unique non-negative integer assigned when the task was created

Return a list of the same task dictionaries, ordered by priority descending and creation_order ascending.

Constraints

  • 0 <= len(tasks) <= 10^5
  • 1 <= priority <= 10
  • 0 <= creation_order < 10^9
  • Each creation_order value is unique

Function Signature

def sort_tasks(tasks):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output