dp
array of length W
(the width of the strings) with all elements set to 1. This represents the minimum number of columns to keep starting from each column.k
, iterate through all columns j
to the right of k
.i
, strs[i][k] <= strs[i][j]
, then update dp[k]
to be the maximum of dp[k]
and dp[j] + 1
.dp
array, find the maximum value in dp
which represents the maximum number of columns to keep.dp
from the total number of columns to get the minimum number of columns to delete.