Problem statement

https://leetcode.com/problems/reorder-data-in-log-files/

Solution

Nothing interesting here, we need to carefully implement what is asked.

Complexity

It is O(n) for time and space, where n is the total length of all logs.

Code

class Solution:
    def reorderLogFiles(self, logs):
        dig, let = [], []

        for log in logs:
            if log.split()[1].isdigit():
                dig += [log]
            else:
                let += [log]
         
        let.sort(key = lambda x: (x.split()[1:], x.split()[0]))
        return let + dig