LeetCode 401 Binary Watch Solution in C++

Day 12 | LeetCode Progress 🚀 Today, I worked on LeetCode 401 – Binary Watch, a problem that focuses on bit manipulation and binary representation. 🧠 Problem Overview A binary watch uses: 4 LEDs to represent hours (0–11) 6 LEDs to represent minutes (0–59) The task was to return all possible valid times where the total number of LEDs turned on equals a given number. 💡 Key Learnings Applied bit manipulation techniques to count set bits efficiently using __builtin_popcount() in C++. Strengthened understanding of binary representation in practical scenarios. Reinforced the importance of clean formatting and edge case handling (e.g., leading zero in minutes, no leading zero in hours). Learned that sometimes a well-structured brute-force approach is both optimal and readable. 🔍 Approach Iterated through all valid hour (0–11) and minute (0–59) combinations and selected those where the total number of set bits matched the input condition. Time Complexity: O(1) (since the search space is fixed at 720 combinations) Consistent practice is helping me improve my logical thinking and problem-solving efficiency every day. 📈 Day 12/100 — Building discipline through daily DSA practice. #100DaysOfCode #DSA #CPlusPlus #LeetCode #ProblemSolving #SoftwareEngineering #ComputerScience

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories