FastPrepCount Sortable Splits
Problems/Count Sortable Splits

Count Sortable Splits

Google logoGoogle● EasyINTERNOA
QuestionFunctionExamples

Problem statement

You are given an integer array A of length N.

Choose one split position that divides A into two non-empty contiguous parts, called left and right. Sort the elements in each part independently in non-decreasing order, then join the sorted left part followed by the sorted right part.

Return the number of split positions for which the joined array is sorted in non-decreasing order.

Function

solution(A: int[]) → int

Examples

Example 1

A = [1, 3, 2, 4]return = 2

There are three possible split positions:

  • left = [1] and right = [3, 2, 4] produce [1, 2, 3, 4], so this split works.
  • left = [1, 3] and right = [2, 4] produce [1, 3, 2, 4], so this split does not work.
  • left = [1, 3, 2] and right = [4] produce [1, 2, 3, 4], so this split works.

Therefore, the answer is 2.

More Google problems

  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int solution(int[] A) {
      // write your code here
    }

}
Checking account…