Greedy using set
cpp\nint n = strs.size();\nint m = strs[0].size();\nint del = 0;\n\n// a set of each index of strs\nset<int> ss;\n\nfor (int i = 1; i < n; ++i)\n\tss.insert(i);
```cpp\nint n = strs.size();\nint m = strs[0].size();\nint del = 0;\n\n// a set of each index of strs\nset<int> ss;\n\nfor (int i = 1; i < n; ++i)\n\tss.insert(i);\n\n// we move from left to right\nfor (int j = 0; j < m && ss.size(); ++j)\n{\n\tbool valid = true;\n\tset<int> strict;\n\t\n\t// for each remaining strs\n\tfor (int i : ss)\n\t{\n\t\t// if the current column violates the requirement,\n\t\tif (strs[i - 1][j] > strs[i][j])\n\t\t\tvalid = false;\n\t\t// record those that are strictly larger indexes.\n\t\telse if (strs[i - 1][j] < strs[i][j])\n\t\t\tstrict.insert(i);\n\t\t\n\t\tif (! valid)\n\t\t\tbreak;\n\t}\n\t\n\t// if the current column is valid, we remove those strictly larger indexes, since they are already be in position.\n\tif (valid)\n\t{\n\t\tfor (int i : strict)\n\t\t\tss.erase(i);\n\t}\n\t// if the current column is invalid, we delete it.\n\telse\n\t\t++ del;\n}\n\nreturn del;\n```\n
['C', 'Ordered Set']