FastPrepMax Chunks to Make Sorted
Problems/Max Chunks to Make Sorted

Max Chunks to Make Sorted

Bloomberg LP logoBloomberg LP● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A senior software engineer's report from a Bloomberg on-site day describes an array question: cut the array into pieces, sort each piece, and the pieces glued back in order must read as the full array from smallest to largest; return the largest number of pieces. It gives two small arrays with their answers and points to the two well-known versions of the task, but it gives no limits.

Everything else here is our practice choice. The two reported arrays are not permutations of 0 to n - 1, so we use the version where the values can be any integers, negative, large or repeated. A piece is a block of neighbouring elements, every element is in exactly one piece, and equal values may sit in different pieces. The array has 1 to 2000 elements, each from -1000000000 to 1000000000.

The judged task matches the report at about 85%.

You are given an integer array arr. Cut it into pieces, where each piece is a block of neighbouring elements and every element belongs to exactly one piece. Then sort each piece on its own, and put the sorted pieces back in their original order.

A cut is valid when the result is the whole array in non-decreasing order. Return the largest number of pieces you can cut the array into.

Function

maxChunksToSorted(arr: int[]) → int

Examples

Example 1

arr = [2,5,1,8,6,7]return = 2

Cut into [2, 5, 1] and [8, 6, 7]. Sorted, they are [1, 2, 5] and [6, 7, 8], and together [1, 2, 5, 6, 7, 8], the whole array in order. No cut into 3 or more pieces works: the 1 at index 2 drags the 2 and the 5 into its piece, and the 6 at index 4 drags the 8 into its piece. The answer is 2.

Example 2

arr = [9,7,6,3,5,2,1]return = 1

The smallest value 1 is last, so the first piece must reach all the way to the end. The array cannot be cut at all. The answer is 1.

Example 3

arr = [1,1,0,3,3]return = 3

Cut into [1, 1, 0], [3] and [3]. Sorted, the pieces give [0, 1, 1], [3], [3], which is the whole array in order. Equal values may sit in different pieces. The answer is 3.

Example 4

arr = [-4,-2,-2,0]return = 4

The array is already in order, so every element can be its own piece, including the equal pair -2, -2. The answer is 4.

Constraints

  • 1 <= arr.length <= 2000
  • -1000000000 <= arr[i] <= 1000000000
  • Values can repeat.

More Bloomberg LP Onsite Interview questions

  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Most Segments That Sort the ArrayRippling · OARippling interview questions
  • Build Maximum Integer from Subsequence (Google India)Google · PHONE SCREENGoogle interview questions
  • Trapping Rain WaterTeradata · ONSITE INTERVIEW
  • Minimum Taps to Water a GardenThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Construct a Tree from Level-Order and Inorder TraversalsSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Minimum Candies by RatingGroww · ONSITE INTERVIEW
  • Allocate Minimum PagesAmazon · ONSITE INTERVIEW
  • Largest Rectangle in HistogramTekion · ONSITE INTERVIEWTekion interview questions
  • Trapping Rain WaterKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Confirmed Profiling Events with First-Observed StartsAnthropic · PHONE SCREEN · ONSITE INTERVIEWAnthropic interview questions

Interview reports that mention this question

  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int maxChunksToSorted(int[] arr) {
        // Write your code here.
    }
}
Checking account…