Reorder Data in Log Files

Medium

Description

Reorder logs so letter-logs come before digit-logs. Letter-logs are sorted lexicographically by content then identifier. Digit-logs keep relative order.

Examples

Input:logs = ["dig1 8 1 5 1","let1 art can","dig2 3 6","let2 own kit dig","let3 art zero"]
Output:["let1 art can","let3 art zero","let2 own kit dig","dig1 8 1 5 1","dig2 3 6"]
Explanation:

Sorted logs.

Input:logs = ["num3 2 4 7","abc1 hello world","xyz2 apple banana","num1 9 3 2","abc1 hello world"]
Output:["abc1 hello world","abc1 hello world","xyz2 apple banana","num3 2 4 7","num1 9 3 2"]
Explanation:

Letter logs are sorted first by content ('hello world' comes before 'apple banana' alphabetically). When content is identical ('abc1 hello world' appears twice), they maintain relative order. Digit logs follow in their original order.

Input:logs = ["z1 final log","a1 1 2 3","b2 4 5 6","m5 middle content","x9 9 8 7"]
Output:["z1 final log","m5 middle content","a1 1 2 3","b2 4 5 6","x9 9 8 7"]
Explanation:

Letter logs ('z1 final log' and 'm5 middle content') are sorted alphabetically by content: 'final log' comes before 'middle content'. All digit logs maintain their original order after the letter logs.

Constraints

  • 1 ≤ logs.length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!