[Python3] Solution with using monotonic stack with comments
\n"""\nThe main idea is to get longest non-decreasing interval.\n\nFor decreasing interval (such an interval that we need to sort) we must the maximum of such i
```\n"""\nThe main idea is to get longest non-decreasing interval.\n\nFor decreasing interval (such an interval that we need to sort) we must the maximum of such interval.\n\nExample:\n\narr: [3,8,9,4,5]\n\n0. [] - empty stack\n1. [3] - it is non-decreasing interval\n2. [3,8] - it is non-decreasing interval\n3. [3,8,9] - it is non-decreasing interval\n4. [3,8,9,4] - it is decreasing interval (9 > 4)\n  4.1. need find position such we will have non-decreasing interval [3,4,8,9] - we need sort [8,9,4]\n       while stack and stack[-1] > a\n  4.2. while we find begin of decreasing interval [8,9,4] we must find max value of such interval\n  4.3. why maximum ?\n    4.3.1. [3,8,9,4,5]. We can insert 5. Now decreasing interval - [8,9,4,5]. We must sort [8,9,4,5]. For [8,9,4] we can stay 9 in stack, and when we will consider element = 5 we will get decreasing interval again [9,5].\n\n"""\n\nclass Solution:\n    def maxChunksToSorted(self, arr: List[int]) -> int:\n        stack = []\n\n        for a in arr:\n            _max = a\n            while stack and stack[-1] > a:\n                top = stack.pop()\n                _max = max(_max, top)\n            \n            \n            stack.append(_max)\n            \n        return len(stack)\n```
['Stack', 'Python3']