[Java] O(n) time O(1) space. 9 lines beats 100%
Based on monotonic stack approach well explained in this post.\n\n\n// 0 ms. 100%\npublic int maxChunksToSorted(int[] arr) {\n    int top = 0;\n    for(int a: a
Based on monotonic stack approach well explained in [this post](https://leetcode.com/problems/max-chunks-to-make-sorted-ii/discuss/595713/Monotonic-stack-solution-with-detailed-explanation).\n\n```\n// 0 ms. 100%\npublic int maxChunksToSorted(int[] arr) {\n    int top = 0;\n    for(int a: arr) {\n        int max = a;\n        while(top > 0 && arr[top - 1] > a) {\n            max = Math.max(max, arr[--top]);\n        }\n        arr[top++] = max;\n    }\n    return top;\n}\n```\n\nTime complexity: O(n)\nSpace complexity: O(1)
['Java']