Leetcode 981 Solution

This article provides solution to leetcode question 981 (delete-columns-to-make-sorted)

https://leetcode.com/problems/delete-columns-to-make-sorted

Solution

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