LeetCode 915, Medium. Topics: Array. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:
Problem
<p>Given an integer array <code>nums</code>, partition it into two (contiguous) subarrays <code>left</code> and <code>right</code> so that:</p>
<ul>
<li>Every element in <code>left</code> is less than or equal to every element in <code>right</code>.</li>
<li><code>left</code> and <code>right</code> are non-empty.</li>
<li><code>left</code> has the smallest possible size.</li>
</ul>
<p>Return <em>the length of </em><code>left</code><em> after such a partitioning</em>.</p>
<p>Test cases are generated such that partitioning exists.</p>
Examples
Constraints
- 2 <= nums.length <= 10^5
- 0 <= nums[i] <= 10^6
- There is at least one valid answer for the given input.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026