Leetcode 769 Max chunks to keep array sorted
sparshgarg23 opened this issue · 1 comments
sparshgarg23 commented
Hi,I tried running your code on different test cases
[2,4,1,6,9,5,7] the expected output is 3 but the solution returns 0
Similarly for [2,1,6,4,3,7] the expected output should be 3 but actual output is 0.
I found these test cases here.
https://leetcode.com/discuss/interview-question/524146/
I think question is similar to 769
kamyu104 commented
- The trick of the solution used in 0769 doesn't work with your problem constraint
"not in range [0, A.size() - 1]"
. - Under that problem constraint, you may use another solution which costs the same
O(n) time
butextra auxiliary O(n) space
for a mono stack to find the number of max chunks.