Dsa
Sorting
Easy
Task Priority Sorting
You are managing a list of tasks where each task has a description and a priority level (integer). Your job is to sort the tasks based on priority in descending order. If two tasks have the same priority, they should retain their input order (stable sort). Print the sorted tasks in the format: 'TaskDescription with priority PriorityLevel'.
Input Format:
- The first line contains an integer N (1 <= N <= 500), the number of tasks.
- The next N lines each contain the task description followed by its priority level.
Output Format:
- Print each task and its priority in the sorted order.
Example:
Input:
4
Fix bugs 2
Write tests 3
Refactor code 2
Code review 1
Output:
Write tests with priority 3
Fix bugs with priority 2
Refactor code with priority 2
Code review with priority 1
Key concepts
sortinglists
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