LeetCode 1356: Sort by Number of 1 Bits 🧮

Sort integers based on the count of 1 bits in their binary form. A bit-based sorting challenge in C++ for Day 56/365.

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

About this video

😄 When numbers get judged not by value but by how many 1s they carry — welcome to bit-based sorting! 💻⚡

LeetCode 1356 | Sort Integers by The Number of 1 Bits | Daily LeetCode | Day 56/365 | Bit Manipulation + Sorting | C++ Solution

In today’s video, we solve LeetCode 1356: Sort Integers by The Number of 1 Bits, where we must sort an array based on the count of set bits in each number.
If two numbers have the same bit count, we sort them by their numeric value.

🧠 Core Idea:
• Count set bits for each number (using builtin / bit trick)
• Sort using a custom comparator
• Primary key → set bit count
• Secondary key → numeric value

A clean mix of bit manipulation + custom sorting.

📌 What you’ll learn in this video:
• Efficient set bit counting methods
• Writing custom comparator functions
• Pair-based sorting approach
• Clean and interview-ready C++ implementation
• Time & space complexity explanation

⏱ Time Complexity: O(n log n)
💾 Space Complexity: O(n)

💻 Problem Link:
https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits/

🎯 Why this problem matters:
This problem strengthens your understanding of bit counting combined with sorting logic, a common pattern in coding interviews and contests.

👍 Like the video if sorting problems are getting easier
💬 Comment if you want more bit manipulation tricks
🔔 Subscribe for the 365 Days of LeetCode Challenge

#LeetCode
#DailyLeetCode
#Day56of365
#BitManipulation
#Sorting
#CPlusPlus
#DSA
#InterviewPreparation

Video Information

Views

54

Likes

3

Duration

5:58

Published

Feb 25, 2026

Related Trending Topics

LIVE TRENDS

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