Ctrl K

Low-High Split Point

Medium
You are given an array of non-negative integers values. Cut it at one position into two non-empty parts, left and right, so that every number in the left part is less than or equal to every number in the right part. There may be several such cuts. Pick the one that makes the left part as short as possible and return its length. At least one valid cut is guaranteed to exist.
Example 1
values=[4, 2, 7, 5, 9] → 2

The left part is [4, 2] and the right part is [7, 5, 9]: the left maximum 4 does not exceed the right minimum 5. Taking just [4] fails because 2 would end up on the right.

Example 2
values=[3, 3, 1, 3, 8] → 3

The 1 must land in the left part, so the left part is [3, 3, 1]; its maximum 3 is not greater than the right minimum, also 3.

Example 3
values=[0, 6] → 1
Constraints
  • 2 ≤ len(values) ≤ 10⁵
  • 0 ≤ values[i] ≤ 10⁶
  • A valid cut exists
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTwo Boards Holding Water MediumZero-Sum Triples MediumTriple Sum Nearest the Target MediumFour Numbers to a Target MediumNext Arrangement in Order Medium
loading Python…
Input
values=[4, 2, 7, 5, 9]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 81 tests on the server, hidden ones included.