Description
Solutions
Process Messages (FrontEnd focused Full-Stack Eng :)
🔥 FULLTIME

You are developing a messaging system that needs to process messages in a specific order. Each message has a timestamp and a priority level (1 to 5, where 1 is highest priority). Messages should be processed based on the following rules: higher priority messages should be processed first, and among messages with the same priority, earlier timestamps should be processed first. Write a function that takes an array of messages (each containing timestamp and priority) and returns them in the correct processing order. Each message in the input array will be in the format: 'timestamp:priority'.

Function Description

Complete the function processMessages in the editor.

processMessages has the following parameter:

  1. String[] messages: an array of strings where each string is in the format 'timestamp:priority'

Returns

String[]: an array of messages in the correct processing order

Requirements:

  • Function should accept an array of strings as input.
  • Each string will be in format 'timestamp:priority' (e.g., '1045:2').
  • Timestamp will be a 4-digit number (0000-9999).
  • Priority will be a single digit from 1-5.
  • Example 1:

    Input:  messages = ["1045:2", "1040:1", "1050:1", "1030:3"]
    Output: ["1040:1", "1050:1", "1045:2", "1030:3"]
    Explanation:
    Messages with priority 1 come first (1040, 1050 ordered by timestamp), followed by priority 2, then priority 3.

    Example 2:

    Input:  messages = ["2000:2", "1000:2", "3000:1", "2000:1"]
    Output: ["2000:1", "3000:1", "1000:2", "2000:2"]
    Explanation:
    Priority 1 messages first (2000, 3000 by timestamp), then priority 2 messages (1000, 2000 by timestamp).
    Constraints:
        :)
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: