values. In one move you may swap two adjacent elements, but only if their binary forms contain the same number of 1s. You may make any number of moves, including none.
Return True if such moves can sort the list in non-decreasing order, and False otherwise.values=[6, 3, 5, 16, 8] → True
6, 3 and 5 each have two 1-bits (110, 11, 101), so they can be rearranged into 3, 5, 6. 16 and 8 each have one 1-bit and can be swapped too, giving [3, 5, 6, 8, 16].
values=[4, 3, 8] → False
4 and 3 would have to trade places, but 4 has one 1-bit and 3 has two, so that swap is not allowed.
values=[10] → True
values=[6, 3, 5, 16, 8]
True
Run checks the first 3 tests in your browser. Submit checks all 135 tests on the server, hidden ones included.