def maxChunksToSorted(self, arr):
    '\n        :type arr: List[int]\n        :rtype: int\n        '
    stacks = []
    for num in arr:
        if (not stacks):
            stacks.append([num])
        elif (num >= stacks[(- 1)][0]):
            stacks.append([num])
        else:
            stacks[(- 1)].append(num)
            while (len(stacks) >= 2):
                if (num < stacks[(- 2)][0]):
                    stacks[(- 2)][0] = max(stacks[(- 2)][0], stacks[(- 1)][0])
                    stacks[(- 2)].extend(stacks.pop())
                else:
                    break
    return len(stacks)
:type arr: List[int]
:rtype: int
def maxChunksToSorted(self, arr):
    '\n        :type arr: List[int]\n        :rtype: int\n        '
    stacks = []
    for num in arr:
        if (not stacks):
            stacks.append([num])
        elif (num >= stacks[(- 1)][0]):
            stacks.append([num])
        else:
            stacks[(- 1)].append(num)
            while (len(stacks) >= 2):
                if (num < stacks[(- 2)][0]):
                    stacks[(- 2)][0] = max(stacks[(- 2)][0], stacks[(- 1)][0])
                    stacks[(- 2)].extend(stacks.pop())
                else:
                    break
    return len(stacks)