hi, let Avik connect you.
** You can give your thought about this content and request modifications if needed from Ask For Modifications page. Thank You.
** You can check all the posts on the Posts page.
** More about me in the About Me section.
Delete Columns to Make Sorted
Problem: 944. Delete Columns to Make Sorted
Problem Link: https://leetcode.com/problems/delete-columns-to-make-sorted/
Companies Asked: Google
Approach:
Traverse through each of the given string's ith position.
Check if the ith character is lesser than the character at (i - 1)th position.
If it is then increase the count by 1.
Return the count.
Time and Space Complexity:
Time Complexity: O(MxN)
Space Complexity: O(1)
Code [C++]
class Solution {
public:
int minDeletionSize(vector<string>& strs) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int colSize = strs[0].size(), rowSize = strs.size();
int cnt = 0;
for(int i=0; i<colSize; i++){
for(int j=1; j<rowSize; j++){
if(strs[j][i] < strs[j-1][i]){
cnt++; break;
}
}
}
return cnt;
}
};