BackmediumBasic Sorting Algorithms basic-sorting-algorithms medium

Timestamp Priority Sort Solution

Problem Statement

Given a list of messages where each message is an object with a unique timestamp and a priority level, implement a sorting function to arrange these messages in ascending order of their timestamps and then by their priority levels in descending order.

Example 1
Input
[{time: 1, priority: 3}, {time: 2, priority: 2}, {time: 1, priority: 4}]
Output
[{time: 1, priority: 4}, {time: 1, priority: 3}, {time: 2, priority: 2}]

Explanation: Messages with the same timestamp are sorted by priority in descending order.

Constraints

  • 1 <= number of messages <= 10^5
  • 1 <= timestamp <= 10^9
  • 1 <= priority <= 10^3
  • All timestamps are unique or comparable for prioritization
  • Priorities are distinct for messages with the same timestamp

More Basic Sorting Algorithms Problems

View all problems →
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free