LeetCode 401 | Binary Watch | Daily LeetCode | Day 48/365 | Backtracking / Bit Manipulation | C++ Solution
In this video, we solve LeetCode 401: Binary Watch, where a binary watch uses LEDs to represent hours and minutes.
Given the number of LEDs that are ON, we must return all possible valid times.
🧠 Core Idea:
• The watch has:
• 4 LEDs for hours (0–11)
• 6 LEDs for minutes (0–59)
• Count the number of set bits
• Generate all valid combinations
• Use bit counting (builtin function) or backtracking
We ensure:
• Hour 12
• Minute 60
• Exactly turnedOn bits are set
📌 What you’ll learn in this video:
• How binary representation maps to time
• Counting set bits efficiently
• Generating combinations smartly
• Validating constraints carefully
• Clean and interview-ready C++ implementation
• Time & space complexity discussion
⏱ Time Complexity: O(1) (bounded by 12 × 60 possibilities)
💾 Space Complexity: O(1)
💻 Problem Link:
https://leetcode.com/problems/binary-watch/
🎯 Why this problem matters:
This problem strengthens your understanding of bit manipulation + combinatorics, commonly asked in interviews to test logical thinking.
👍 Like the video if bit problems are becoming fun
💬 Comment if you want a dry run example
🔔 Subscribe for the 365 Days of LeetCode Challenge
#LeetCode
#DailyLeetCode
#Day48of365
#BitManipulation
#Backtracking
#Binary
#CPlusPlus
#DSA
#InterviewPreparation