3994. Minimum Adjacent Swaps to Partition Array
You are given an integer array
numsand two integersaandbsuch thata < b.An array is called good if it can be split into three contiguous parts, in this order, such that:
- Every element in the first part is less than
a.- Every element in the second part is in the range
[a, b]inclusive.- Every element in the third part is greater than
b.Any of the three parts may be empty.
In one adjacent swap, you may swap two neighboring elements of
nums.Return the minimum number of adjacent swaps required to make
numsgood. Since the answer may be very large, return it modulo10^9 + 7.
1 | class Solution { |