You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You are given an N by M 2D matrix of lowercase letters. Determine the minimum number of columns that can be removed to ensure that each row is ordered from top to bottom lexicographically. That is, the letter at each column is lexicographically later as you go down each row. It does not matter whether each row itself is ordered lexicographically.
3
-
4
-
For example, given the following table:
5
-
6
-
cba
7
-
daf
8
-
ghi
9
-
This is not ordered because of the a in the center. We can remove the second column to make it ordered:
10
-
11
-
ca
12
-
df
13
-
gi
14
-
So your function should return 1, since we only needed to remove 1 column.
15
-
16
-
As another example, given the following table:
17
-
18
-
abcdef
19
-
Your function should return 0, since the rows are already ordered (there's only one row).
20
-
21
-
As another example, given the following table:
22
-
23
-
zyx
24
-
wvu
25
-
tsr
26
-
Your function should return 3, since we would need to remove all the columns to order it.
1
+
80
2
+
Given the root of a binary tree, return a deepest node. For example, in the following tree, return d.
0 commit comments