[C++] Easy to Understand Greedy Approach
Consider ["xga","xfb","yfa"]\nColumn wise push characters into the vector of strings\nCheck if this vector is sorted. If it is not sorted then delete the curren
Consider ["xga","xfb","yfa"]\nColumn wise push characters into the vector of strings\nCheck if this vector is sorted. If it is not sorted then delete the current column\nSo iteration 1: ["x","x","y"] This vector is sorted so no deletion\nIteration 2: ["xg","xf","yf"] This vector is not sorted.So delete the current colum. So final vector ["x","x","y"]\nIteration 3: ["xa","xb","ya"] This vector is already sorted.\nThis way total number of deletions is 1.\n\nclass Solution {\npublic:\n\n    bool check(vector<string> str)\n    {\n        for(int i=1;i<str.size();i++)\n        {\n            if(str[i]<str[i-1]) return false;\n        }\n        return true;\n    }\n    \n    int minDeletionSize(vector<string>& A) {\n     int count=0;int len=A[0].length();\n     vector<string>full_sorted(A.size());\n     for(int i=0;i<len;i++)\n     {\n         //temp is a vector containing all the strings in sorted order\n         vector<string>temp=full_sorted;//Initialize temp :Copy full_sorted to temp before adding the next character \n         for(int k=0;k<A.size();k++) temp[k]+=A[k][i]; \n         if(check(temp)) full_sorted=temp;  //If already sorted then update full_sorted   \n         else count++;\n     }\n    return count;\n    }\n    };
[]