I have an array 'logs', where logs = ["1 art can", "2 own kit dig", "3 art zero", "4 art can"]. Each element is a string which has a serial number, followed by a bunch of words. I need to sort the array in the lexicographical order of the string contents (excluding the serial number). If two strings in the array have the same content, I need to sort them based on their serial numbers.
I used the sort() function in combination with a lambda function which in turn uses the split() function. Usage below:
logs.sort(key=lambda x: (x.split()[1:], x.split()[0]))
I know that the time complexity of sort() is O(nlog(n)) and split() itself has a O(n) time complexity. Assuming there are n strings, each of length m, what is the effective time complexity of logs.sort(key=lambda x: (x.split()[1:], x.split()[0]))?