📌📌 Easy-to-Understand || 98% faster || Well-Explained 🐍
IDEA:\nTake this [ 2, 1, 7, 6, 3, 5, 4, 9, 8 ] as an example and once try yourself to split it into maximum chunks using stack.\n\nYou will come to following co
## IDEA:\n**Take this [ 2, 1, 7, 6, 3, 5, 4, 9, 8 ] as an example and once try yourself to split it into maximum chunks using stack.**\n\nYou will come to following conclusions : \n* The max number in the left chunk must always be <= the max number in the right chunk. \n\n* We only need to maintain the max number of each chunk in the stack. This is because if num[i] >= stack[-1], then num[i] must be bigger than all other elements in that chunk. \n* Otherwise if num[i] < stack[-1], then it must belong to the previous chunk regardless of whether num[i] is bigger than the other elements or not. Hence, only the max num in each chunk is relevant.\n\n**Implementation:**\n\n* So, we can loop through the array and maintain a stack. Each element in the stack represents a chunk.\n\n* Each time we encounter a num[i] that is bigger than or equal to the previous chunk max, we push it to the stack. If we encounter a smaller number, we must combine this number with the previous chunks. We do this by comparing with the top chunk in the stack and popping them off until we encounter a chunk with max number that is smaller than num[i]. \n* Then, we update the new combined chunk with the new max by pushing it back onto the stack. The number of elements in this stack at the end is the number of chunks.\n\n### CODE:\n\'\'\'\n\n\tclass Solution:\n    def maxChunksToSorted(self, nums: List[int]) -> int:\n        \n        st = []\n        for n in nums:\n            if len(st)==0 or st[-1]<=n:\n                st.append(n)\n            else:\n                ma = st[-1]\n                while st and st[-1]>n:\n                    ma = max(ma,st.pop())\n                st.append(ma)\n        \n        return len(st)\n\n**Thanks and *Upvote* if you like the idea!!\uD83E\uDD1E**
['Stack', 'Python', 'Python3']