Max Chunks To Make Sorted II

Max Chunks To Make Sorted II

Given an array of integers arr (which may contain duplicates), we want to split the array into a number of contiguous chunks such that if we sort each chunk individually and concatenate them, the resulting array is sorted in non-decreasing order. Your goal is to find the maximum number of chunks that can be created to satisfy this condition. Example: Input: arr = [2, 1, 3, 4, 4] Output: 4 Explanation: We can split into [2, 1], [3], [4], [4]. Sorting each gives [1, 2], [3], [4], [4], which concatenated is [1, 2, 3, 4, 4]. Constraints: 1 <= arr.length <= 10^5 0 <= arr[i] <= 10^8
SwiftPrefix SumSuffix Min
00
Read
1
InterviewGPT

AI-powered tools to help you succeed in tech interviews — from resume to offer.

Interview Solver

  • Coding Puzzles
  • System Design
  • Behavioral Challenges
  • ML System Design
  • SQL Puzzles
  • FE System Design
Explore Solver

Question Bank

  • Coding Interview Questions
  • System Design Interview Questions
  • Behavioral Interview Questions
  • ML System Design Questions
  • SQL & Database Questions
  • FE System Design Questions
Explore Questions

Golden Blogs

  • Coding Solutions
  • System Design Guides
  • Behavioral Guides
  • ML System Design Guides
  • SQL Solutions
  • FE System Design Guides
Explore Blogs

Intervipedia

  • Coding Concepts
  • System Design Concepts
  • Behavioral Concepts
  • ML System Concepts
  • SQL Concepts
  • FE System Concepts
Explore Concepts

Application Tools

  • Self-Intro Generator

Company

  • Pricing
  • FAQ
  • About
  • Privacy Policy
  • Terms of Service

© 2026 InterviewGPT Inc. All rights reserved.

All systems operationalUS-East

Made with ♥ for developers