<p>You are given an array of <code>n</code> strings <code>strs</code>, all of the same length.</p>

<p>We may choose any deletion indices, and we delete all the characters in those indices for each string.</p>

<p>For example, if we have <code>strs = [&quot;abcdef&quot;,&quot;uvwxyz&quot;]</code> and deletion indices <code>{0, 2, 3}</code>, then the final array after deletions is <code>[&quot;bef&quot;, &quot;vyz&quot;]</code>.</p>

<p>Suppose we chose a set of deletion indices <code>answer</code> such that after deletions, the final array has <strong>every string (row) in lexicographic</strong> order. (i.e., <code>(strs[0][0] &lt;= strs[0][1] &lt;= ... &lt;= strs[0][strs[0].length - 1])</code>, and <code>(strs[1][0] &lt;= strs[1][1] &lt;= ... &lt;= strs[1][strs[1].length - 1])</code>, and so on). Return <em>the minimum possible value of</em> <code>answer.length</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> strs = [&quot;babca&quot;,&quot;bbazb&quot;]
<strong>Output:</strong> 3
<strong>Explanation:</strong> After deleting columns 0, 1, and 4, the final array is strs = [&quot;bc&quot;, &quot;az&quot;].
Both these rows are individually in lexicographic order (ie. strs[0][0] &lt;= strs[0][1] and strs[1][0] &lt;= strs[1][1]).
Note that strs[0] &gt; strs[1] - the array strs is not necessarily in lexicographic order.</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> strs = [&quot;edcba&quot;]
<strong>Output:</strong> 4
<strong>Explanation:</strong> If we delete less than 4 columns, the only row will not be lexicographically sorted.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> strs = [&quot;ghi&quot;,&quot;def&quot;,&quot;abc&quot;]
<strong>Output:</strong> 0
<strong>Explanation:</strong> All rows are already lexicographically sorted.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == strs.length</code></li>
	<li><code>1 &lt;= n &lt;= 100</code></li>
	<li><code>1 &lt;= strs[i].length &lt;= 100</code></li>
	<li><code>strs[i]</code> consists of lowercase English letters.</li>
</ul>

<ul>
	<li>&nbsp;</li>
</ul>

class Solution {
public:
    //int minDeletionSize(vector<string>& strs) {
/*int print0(vector<string> b,int c,int e,int temp18){
    if(c==temp18){
        return 0;
    }
    int temp0=0;
    int temp2=0;
    if(e==-1){
        temp0=min(print0(b,c+1,c,temp18),print0(b,c+1,e,temp18)+1);
    }
    else if(e!=-1){
        for(int temp12=0;temp12<b.size();temp12++){
            if(c<b[temp12].size() && b[temp12][c]>=b[temp12][e]){
                continue;
            }
            else if(c<b[temp12].size() && b[temp12][c]<b[temp12][e]){
                temp2=1;
            }
        }
    }
    //cout<<temp2<<" ";
    //cout<<c<<" ";
    if(temp2==0){
        temp0=min(print0(b,c+1,c,temp18),print0(b,c+1,e,temp18)+1);
    }
    else if(temp2==1){
        temp0=print0(b,c+1,e,temp18)+1;
    }
    //cout<<temp0<<" ";
    return temp0;
}
int minDeletionSize(vector<string> b){
    int c=0;
    int e=-1;
    int temp0=0;
    int temp2=0;
    int temp12=0;
    for(int temp18=0;temp18<b.size();temp18++){
        temp12=max(temp12,int(b[temp18].size()));
    }
    temp0=print0(b,c,e,temp12);
    return temp0;
    }*/
    int print0(vector<string> &b,vector<vector<int>> &c,int e,int temp0,int temp12){
    if(e==temp12){
        return 0;
    }
    int temp18=0;
    int temp28=0;
    if(temp0!=-1){
        if(c[e][temp0]!=-1){
            return c[e][temp0];
        }
    }
    else if(temp0==-1){
        if(c[e][e]!=-1){
            return c[e][e];
        }
    }
    if(temp0==-1){
        temp18=min(print0(b,c,e+1,e,temp12),print0(b,c,e+1,temp0,temp12)+1);
    }
    else if(temp0!=-1){
        for(int temp48=0;temp48<b.size();temp48++){
            if(e<b[temp48].size() && b[temp48][e]>=b[temp48][temp0]){
                continue;
            }
            else if(e<b[temp48].size() && b[temp48][e]<b[temp48][temp0]){
                temp28=1;
            }
        }
    }
    if(temp28==0){
        temp18=min(print0(b,c,e+1,e,temp12),print0(b,c,e+1,temp0,temp12)+1);
    }
    else if(temp28==1){
        temp18=print0(b,c,e+1,temp0,temp12)+1;
    }
    if(temp0!=-1){
        c[e][temp0]=temp18;
    }
    else if(temp0==-1){
        c[e][e]=temp18;
    }
    //cout<<e<<" ";
    //cout<<temp0<<" ";
    return temp18;
}
int minDeletionSize(vector<string> b){
    vector<vector<int>> c;
    int e=0;
    int temp0=-1;
    int temp2=0;
    int temp12=0;
    int temp72=0;
    for(int temp18=0;temp18<b.size();temp18++){
        temp12=max(temp12,int(b[temp18].size()));
    }
    for(int temp18=0;temp18<temp12;temp18++){
        vector<int> temp28;
        for(int temp48=0;temp48<temp12;temp48++){
            temp28.push_back(-1);
        }
        c.push_back(temp28);
    }
    temp72=print0(b,c,e,temp0,temp12);
    return temp72;
}
};
29300