Find if Array Can Be Sorted
You are given a 0-indexed array of positive integers nums.
In one operation, you can swap any two adjacent elements if they have the same number of set bits (i.e., the same popcount in their binary representation).
Return true if you can sort the array in non-decreasing order using these operations; otherwise, return false.
Examples
Input: [8,4,2,30,15]
Output: true
Input: [3,16,8,4,2]
Output: false
Hints
Group consecutive elements with the same popcount together. Each group can be rearranged arbitrarily since adjacent swaps within the group can achieve any permutation.
After sorting each group independently, check if the entire array becomes sorted.
The key restriction is that elements with different popcounts cannot cross each other.
Find if Array Can Be Sorted
You are given a **0-indexed** array of **positive** integers `nums`.