Ideas from Selection Sort
Selection Sort is a common N^2 sorting technique with the following based premise: find the minimum element of an array (O(N)), move it to be the first. Repeat this for the remaining elements (O(N), hence the total is N^2). In this problem we can use the exact same idea, the only variation is that you need to pre-compute the number-to-countBits for every number, and ensure that the path to move the element to becoming the first adheres to the problem statement (along the way all the numbers need to have the same number of Bits, which you can then make use of the pre-computed map). Code is down below, cheers, ACC. Find if Array Can Be Sorted - LeetCode 3011. Find if Array Can Be Sorted Medium 69 8 Add to List Share 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 . You are allowed to do this operation an...