π₯ **Sort by Set Bit Count | Coding Interview Question (Java)**
In this video, we solve an important interview problem:
π Sort an array based on the number of set bits (1s) in binary representation.
π **Problem Statement:**
Given an array of integers, sort the array in **descending order of set bits**.
If two numbers have the same number of set bits, maintain their **original order (stable sort)**.
π₯ **Input:**
arr[] = [5, 2, 3, 9, 4, 6, 7, 15, 32]
π€ **Output:**
15 7 5 3 9 6 2 4 32
π‘ **Concepts Covered:**
β Bit Manipulation
β Counting Set Bits
β Stable Sorting
β Custom Comparator in Java
π This question is frequently asked in coding interviews and helps improve your problem-solving skills.
π Like | Share | Subscribe for more coding problems!
#coding #java #interviewquestions #dsa #bitmanipulation
Question Link
https://www.geeksforgeeks.org/problems/sort-by-set-bit-count1153/1