LeetCode 1356: Sort by Number of 1 Bits 🧮

Learn to solve LeetCode 1356, sorting integers based on the count of 1 bits, with a clear Java explanation. Easy level!

LeetCode 1356: Sort by Number of 1 Bits 🧮
leetcoder_pooja
0 views • Feb 25, 2026
LeetCode 1356: Sort by Number of 1 Bits 🧮

About this video

🚀 **LeetCode 1356 | Sort Integers by The Number of 1 Bits | Easy | Java Explanation**

In this video, we solve **LeetCode Problem 1356 – Sort Integers by The Number of 1 Bits** using Java and understand the logic step-by-step.

🔍 **Problem Idea:**
We are given an array of integers. We must sort the numbers:
1️⃣ Based on the **number of 1s (set bits)** in their binary representation.
2️⃣ If two numbers have the same number of 1s, sort them in **ascending numerical order**.

💡 This problem helps you understand:

* Binary representation of numbers
* Counting set bits using `Integer.bitCount()`
* Custom sorting with **Lambda Comparator** in Java
* How to sort based on multiple conditions (important for interviews!)

🧠 **Concepts Covered:**
✔ Bit Manipulation Basics
✔ Custom Sorting in Java
✔ Comparator & Lambda Functions
✔ Time Complexity Analysis
✔ Dry Run Example Explanation

📌 **Example:**
Input: `[0,1,2,3,4,5,6,7,8]`
Output: `[0,1,2,4,8,3,5,6,7]`

---

⏱ **Timestamps:**
00:00 – Problem Explanation
01:20 – Understanding Binary & Set Bits
03:10 – Approach & Logic
05:00 – Java Code Walkthrough
08:00 – Dry Run Example
10:15 – Complexity Analysis
11:00 – Interview Tips

---

🔥 Practice this problem here:
LeetCode #1356 – Sort Integers by The Number of 1 Bits

---

📚 Follow for more Data Structures & Algorithms explanations, coding interview prep, and daily LeetCode solutions!

#LeetCode #DSA #JavaProgramming #BitManipulation #CodingInterview #GeekStreak #ProblemSolving #LearnToCode #WomenInTech #CSE

Video Information

Views

0

Duration

3:17

Published

Feb 25, 2026

Related Trending Topics

LIVE TRENDS

Related trending topics. Click any trend to explore more videos.