Delete Columns to Make Sorted

Problem Id: 944 Difficulty: Easy


Intuition

Solution


class Solution:
    def minDeletionSize(self, A: List[str]) -> int:
        ans = 0
        for i in range(len(A[0])):
            last = A[0][i]
            for j in range(len(A)):
                if A[j][i] < last:
                    ans += 1
                    break
                last = A[j][i]
        return ans