InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Max Chunks To Make Sorted II

Given an array of integers (not necessarily distinct) A,
if we split the array into some number of “chunks” (partitions), and individually sort each chunk.
After concatenating them, the result equals the sorted array.

What is the most number of chunks we could have made?

Input Format

The only argument given is the integer array A.

Output Format

Return the maximum number of chunks that we could have made.


1 <= N <= 100000
-10^9 <= A[i] <= 10^9

For Example

Input 1:
    A = [3, 2, 3, 4, 0]
Output 1:

Input 2:
    A = [2, 0, 1, 2]
Output 2:
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Max Chunks To Make Sorted II on Interview Code Editor
Sign Up
to access hints and editorial solutions for Max Chunks To Make Sorted II


Click here to start solving coding interview questions