Skip to content

769. Max Chunks To Make Sorted #973

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find the largest number of chunks that can be formed such that each chunk can be sorted individually, and when concatenated, the result is the sorted version of the entire array.

Approach:

  1. Key Observation:

    • The array is a permutation of integers from 0 to n-1. The idea is to traverse the array and find positions where the chunks can be separated.
    • A chunk can be sorted if, for all indices within the chunk, the maximum element up to that point does not exceed the minimum element after that point in the original sorted array.
  2. Strategy:

    • Track the maximum value encountered as you traverse from left to right.
    • At each index i, check if the maximum value up to i is less than or e…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Dec 19, 2024
Collaborator

@mah-shamim
Comment options

mah-shamim Dec 19, 2024
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants