Approach 1: Custom Sort

Intuition and Algorithm

Instead of sorting in the default order, we'll sort in a custom order we specify.

The rules are:

  • Letter-logs come before digit-logs;
  • Letter-logs are sorted alphanumerically, by content then identifier;
  • Digit-logs remain in the same order.

It is straightforward to translate these ideas into code.

Complexity Analysis

  • Time Complexity: , where is the total content of logs.

  • Space Complexity: .

Analysis written by: @awice.