Problem statement

https://binarysearch.com/problems/Column-Sort/

Solution

Rotate matrix, sort each row and then rotate back.

Complexity

It is O(nm log n) for time and O(nm) for space.

Code

class Solution:
    def solve(self, M):
        return [x for x in zip(*(sorted(col) for col in zip(*M)))]