Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Compute the popcount (number of set bits) for each integer using Brian Kernighan's algorithm. Sort the array with a custom comparator that orders by ascending popcount first, then by ascending numeric value for ties.
The comparator encodes a two-level sort key: primary key is the number of 1-bits, secondary key is the integer value itself, producing a stable ordering by bit density.
Updated Feb 2026