single pass minimum operations
Intuition\n\nwe only compare the same character position on consecutive strings, unless the pair of strings is already sorted (a previously kept index has sorte
# Intuition\n\nwe only compare the same character position on consecutive strings, unless the pair of strings is already sorted (a previously kept index has sorted characters), the we don\'t need to check further characters in that pair of strings anymore.\n\n# Approach\n\n* for each character index `i` we only need to compare `strs[j][i]` with `strs[j+1][i]` (same character position on consecutive strings)\n* if `strs[j][i] > strs[j+1][i]`, index `i` NEEDS to be removed\n* if the index `i` does not need to be removed:\n    * if `strs[j][i] == strs[j+1][i]`, we still need to compare `strs[j][i+x]` with `strs[j+1][i+x]` (following character positions on the same pair of strings)\n    * if `strs[j][i] < strs[j+1][i]`, that pair of strings is ordered, and we do not need to compare more characters\n\nwe only need to track the numbers of indices to delete (`toDelete`) and the string pairs already cleared by a prior non deleted index (`cleared`)\n\n# Complexity\n- Time complexity:\n$$O(m.n)$$ (m being the string length)\n\n- Space complexity:\n$$O(n)$$ (tracking cleared pairs)\n\n# Code\n```typescript []\nfunction minDeletionSize(strs: string[]): number {\n    if(strs.length < 2)\n        return 0;\n    let toDelete = 0;\n    let cleared = new Array(strs.length-1).fill(false);\n    for (let i = 0; i < strs[0].length; ++i) {\n        for (let j = 0; j < strs.length; ++j) {\n            if(j == strs.length - 1) {\n                cleared = cleared.map((c, k) => c || strs[k].charCodeAt(i) < strs[k+1].charCodeAt(i))\n                if(cleared.every(x=>x))\n                    return toDelete;\n                break;\n            }\n            if(cleared[j])\n                continue;\n            if(strs[j].charCodeAt(i) > strs[j+1].charCodeAt(i)) {\n                toDelete += 1;\n                break;\n            }\n        }\n    }\n    return toDelete;\n};\n```
['TypeScript']