Back to Browse

πŸ”₯ Sort Array by Set Bit Count | Java Interview Question

12 views
Apr 13, 2026
13:19

πŸ”₯ **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

Download

1 formats

Video Formats

360pmp410.2 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

πŸ”₯ Sort Array by Set Bit Count | Java Interview Question | NatokHD