Tap here to switch tabs
Problem
Submissions

Problem: Minimum Adjacent Swaps to Partition Array

Try to solve the Minimum Adjacent Swaps to Partition Array problem.

Statement

You are given an integer array nums and two integers a and b such that a << b.

An array is considered partitioned if it can be divided into three contiguous segments:

  1. The first segment contains all elements strictly less than a.

  2. The second segment contains all elements greater than or equal to a and less than or equal to b.

  3. The third segment contains all elements strictly greater than b.

In one operation, you may swap any two adjacent elements in nums.

Return the minimum number of adjacent swaps required to make nums partitioned.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq a << b ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Adjacent Swaps to Partition Array

Try to solve the Minimum Adjacent Swaps to Partition Array problem.

Statement

You are given an integer array nums and two integers a and b such that a << b.

An array is considered partitioned if it can be divided into three contiguous segments:

  1. The first segment contains all elements strictly less than a.

  2. The second segment contains all elements greater than or equal to a and less than or equal to b.

  3. The third segment contains all elements strictly greater than b.

In one operation, you may swap any two adjacent elements in nums.

Return the minimum number of adjacent swaps required to make nums partitioned.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq a << b ≤109\leq 10^9