Find Number of Ways to Split Array
Updated
Problem statement
You are given an array A of N integers. You can split the array into two non-empty parts, left and right, sort the elements in each part independently and join them back together.
Your task is to find the number of ways of splitting the array into two parts such that, after sorting the two parts and rejoining them into a single array, the resulting array will be sorted in non-decreasing order. For the array shown above, the answer is 2: the first and third splits result in a sorted array.
Function
findNumberOfWaysToSplitArray(A: int[]) → intExamples
Example 1
A = [1, 3, 2, 4]return = 2There are two ways to split the array such that the resulting array is sorted:
- Splitting into left = [1] and right = [3, 2, 4], resulting in [1, 2, 3, 4].
- Splitting into left = [1, 3, 2] and right = [4], resulting in [1, 2, 3, 4].
Therefore, the number of ways to split the array is 2.
Constraints
2 <= A.length <= 10^5-10^9 <= A[i] <= 10^9
More Google interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Minimum Seats for One-Way Car PoolingSquadStack.ai · OA
- Choose ContainersIMC Trading · OAIMC Trading interview questions
- Find Network CallsAmazon · OA
- Calculating QuantilesIndeed · OAIndeed interview questions
- Count Lamps Lighting Each PointCapital One · OACapital One interview questions
- Minimum Cost to Make Array EqualWalmart · OAWalmart interview questions
- Temporal AnomaliesInMobi · OAInMobi interview questions
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- Majority Labels over Audio IntervalsNooks · PHONE SCREEN