Dsa
Sorting
Warm-up
Sort Task Priorities
A project management tool needs to sort a list of tasks based on their priorities. Write a program that sorts tasks in ascending order based on their priority levels. If two tasks have the same priority, sort them alphabetically by task name.
Input:
The first line contains an integer T, the number of tasks. The next T lines each contain a task name (a string) followed by its priority (an integer).
Output:
Print the sorted list of tasks with their priorities, one per line, in the format 'TaskName Priority'.
Example:
Input:
3
Design 2
Implement 1
Test 3
Output:
Implement 1
Design 2
Test 3
Key concepts
sortingpriorityarrays
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now