Problem · Array

Count Sortable Splits

EasyGoogleINTERNOA
See Google hiring insights

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.

The problem statement continues
Pro

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.

Original screenshot from the interview report
Pro
FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • Worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • Worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week