Given a nums, you may perform swaps on adjacent elements any number of times.
An array is considered valid if it satisfies both of the following conditions:
The smallest element (or any one of the smallest elements, if duplicates exist) is located at the leftmost position of the array.
The largest element (or any one of the largest elements, if duplicates exist) is located at the rightmost position of the array.
Return the minimum number of adjacent swaps needed to make nums a valid array.
Constraints:
nums.length
nums[i]
Given a nums, you may perform swaps on adjacent elements any number of times.
An array is considered valid if it satisfies both of the following conditions:
The smallest element (or any one of the smallest elements, if duplicates exist) is located at the leftmost position of the array.
The largest element (or any one of the largest elements, if duplicates exist) is located at the rightmost position of the array.
Return the minimum number of adjacent swaps needed to make nums a valid array.
Constraints:
nums.length
nums[i]