Created
January 31, 2018 06:44
-
-
Save jianminchen/7d1d3f8120b7d6ade4f60a4d2de4d6a8 to your computer and use it in GitHub Desktop.
max min - linear time algorithm - maximum number of chunks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[2, 1, 3, 5, 4], size N, element of array is 1 to N, no duplicate | |
[2, 1], [3], [5, 4] | |
what is maximum number of chunk? | |
max[i] -> max to this point | |
min[i] -> min to this point from left | |
2,2,3,5,5 | |
1,1,3,4,4 | |
int chunks=0; | |
for(int i=0; i <nums.Length-1) | |
{ | |
if(max[i] < min[i+1]) | |
chunks++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment