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
LeetCode 401 Binary Watch Solution in C++
More Relevant Posts
-
💻 Day 14 – LeetCode Practice Solved Reverse String (LeetCode 344) today. The task was to reverse a character array in-place without using extra memory. I implemented the two-pointer approach: One pointer starts from the beginning. Another pointer starts from the end. Swap the characters and move both pointers towards the center. This approach ensures an efficient in-place reversal. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) Small problem, but it strengthens understanding of two-pointer techniques and in-place operations. Consistency is the real key 🔁🚀 #LeetCode #CPlusPlus #DSA #TwoPointer #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 4 of My LeetCode Consistency Journey Today I solved LeetCode 151 – Reverse Words in a String (Medium). This problem focuses on: String manipulation Handling extra spaces Efficient traversal Edge case management 💡 Key Learning: Understanding how to properly parse words, remove leading/trailing spaces, and reconstruct the string efficiently improves logical thinking and strengthens DSA fundamentals. Instead of relying on built-in shortcuts, I focused on: ✔️ Clean logic ✔️ Optimized approach ✔️ Handling edge cases carefully Consistency > Motivation 💯 #LeetCode #DSA #ProblemSolving #CodingJourney #Cplusplus #100DaysOfCode #SoftwareEngineering #TechGrowth
To view or add a comment, sign in
-
Day 40 / 100 – LeetCode Challenge 🚀 Problem Solved: Check if All Characters Have Equal Number of Occurrences (LeetCode 1941) Goal: Check whether every character in the string appears the same number of times. Approach: – Use a map to store frequency of each character – Count occurrences while traversing the string – Compare the frequency of all characters with the first stored frequency – If any frequency differs → return false Concepts Used: • Hash Map • Frequency Counting • String Traversal Performance: ⚡ Runtime: 3 ms 🧠 Memory: 9.55 MB Another small step in the 100 Days of LeetCode Challenge. Consistency and daily practice make the difference. #100DaysOfCode #LeetCode #DSA #CPlusPlus #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 5 of My LeetCode Journey Today I solved LeetCode 150 – Evaluate Reverse Polish Notation (Medium). This problem strengthened my understanding of: Stack data structure Postfix expression evaluation Operator handling (+, -, *, /) Edge case management (negative numbers & division) 💡 Key Learning: Reverse Polish Notation removes the need for parentheses, but requires strong stack logic and careful operand order handling. This problem reinforced how powerful stacks are in expression evaluation and real-world compiler logic. Consistency is the real game changer. On to Day 5 🚀 #LeetCode #DSA #Stacks #ProblemSolving #Cplusplus #CodingJourney #SoftwareEngineering #100DaysOfCode
To view or add a comment, sign in
-
🚀 LeetCode Daily Challenge 🔗 Problem: https://lnkd.in/gR-ZeuhX 💡 My thought process: The approach involves checking all possible valid times that can show on a binary watch. We select the times where the number of LEDs turned on matches the given value. A binary watch displays hours from 0 to 11 and minutes from 0 to 59, so we look at every possible hour and minute combination. For each pair, we count how many bits are set to 1 in the binary representation of the hour and the minute using the built-in `__builtin_popcount()` function. If the total number of set bits in the hour and minute equals the input `turnedOn`, that time is valid. When creating the time string, we add the hour normally, but the minute must always be in two-digit format. A leading zero is added when the minute value is less than 10. We store all valid formatted times in a result list and return it at the end. 👉 My Solution: https://lnkd.in/gN6FMYtF If you found this breakdown helpful, feel free to ⭐ the repo or connect with me on LinkedIn 🙂🚀 #️⃣ #leetcode #cpp #dsa #coding #problemsolving #engineering #BDRM #BackendDevWithRahulMaheswari
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Challenge – Binary Gap 📌 Problem: Binary Gap 🔗 LeetCode - Daily Question Today’s problem focused on analyzing binary representation using bit manipulation. The goal: Find the maximum distance between two consecutive set bits (1s) in a number’s binary form. Brute force string conversion? Possible—but unnecessary. ❌ Bitwise traversal? Clean and optimal. ✅ 💡 Key Insight: - Traverse bits from LSB to MSB - Track the position of the last seen "1" - For every new "1", compute distance from previous - Maintain the maximum gap 🛠 Approach: • Iterate while "n > 0" • Check "(n & 1)" for set bit • Track positions using a counter • Update max distance • Right shift "n" ⏱ Complexity: Time: O(log n) Space: O(1) ✔ Accepted ✔ Clean bit manipulation logic ✔ Reinforced fundamentals of binary traversal Takeaway: Sometimes the simplest bit tricks outperform heavier approaches—clarity wins. Practicing DSA daily with LeetCode, learning alongside CoderArmy, and guided by Rohit Negi, Aditya Tandon Day 26 done. Staying consistent. 🚀 #Day26/90 #LeetCode #DSA #BitManipulation #ProblemSolving #CPlusPlus #LearningInPublic #ProblemSolving2026
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Challenge 🔗 Problem: https://lnkd.in/gTrw45pn 💡 My thought process: We check each bit one by one and compare it with the previous bit. We start with prevBit initialized to -1 which means we haven't seen any bit yet. We loop until n becomes 0 and in each iteration we get the rightmost bit using bitwise AND with 1. If the current bit equals the previous bit then we immediately return false because the bits are not alternating. Otherwise we save the current bit as the previous bit for the next comparison and remove the rightmost bit by right shifting n by 1 position. If we complete the entire loop without finding two consecutive same bits then we return true indicating all bits are alternating. 👉 My Solution: https://lnkd.in/gQpKAMSi If you found this breakdown helpful, feel free to ⭐ the repo or connect with me on LinkedIn 🙂🚀 #️⃣ #leetcode #cpp #dsa #coding #problemsolving #engineering #BDRM #BackendDevWithRahulMaheswari
To view or add a comment, sign in
-
-
Day 1 of #30DaysOfLeetCode Solved #2. Add Two Numbers on LeetCode using C. Approach: • Used Linked List traversal to process both numbers digit by digit • Added digits from both lists along with a carry value • Created new nodes dynamically to store each result digit • Handled cases where lists have different lengths • Continued the loop until both lists and carry were processed Performance: • Runtime: 0 ms (Beats 100% submissions) • Memory: 13.50 MB (Beats 8.30% submissions) Key Learning: • Strengthened understanding of Linked Lists and pointer manipulation • Learned how to manage carry during digit addition • Improved problem-solving skills with dynamic node creation Learning one problem every day 💻🔥 #30DaysOfCode #LeetCode #CProgramming #DSA #LinkedList #ProblemSolving
To view or add a comment, sign in
-
-
Day 10 | Round 5 — 30 Days Coding Challenge 🚀 Today I solved the problem: Minimum Changes to Make Alternating Binary String. Problem (In Simple Words) We are given a binary string consisting of only '0' and '1'. Our task is to convert this string into an alternating string using the minimum number of operations. An alternating string means no two adjacent characters are the same. Examples of valid alternating strings: 010101 101010 In one operation, we can change any character from '0' to '1' or from '1' to '0'. Logic I Used An alternating binary string can only follow two possible patterns: Pattern 1: Start with '0' Example: 010101... Pattern 2: Start with '1' Example: 101010... So instead of modifying the string step by step, I compared the given string with both patterns. Steps: Traverse the string from left to right. For each index, determine the expected character for both patterns. Count mismatches for: Pattern starting with '0' Pattern starting with '1' The minimum of these two counts gives the required number of operations. Why This Approach Works Since only two valid alternating patterns exist, counting mismatches against both patterns directly gives the minimum changes needed. Time Complexity: O(n) Space Complexity: O(1) Round 5 — Day 10 Completed. This problem is a good reminder that sometimes identifying all possible valid outcomes first can greatly simplify the solution. #30DaysOfCode #Round5 #Day10 #Strings #Greedy #DSA #ProblemSolving #LeetCode #CodingChallenge #CPlusPlus #DeveloperJourney #Consistency #CodeDaily #LearnInPublic #TechGrowth
To view or add a comment, sign in
-
-
LeetCode Daily | Day 43 🔥 LeetCode POTD – 693. Binary Number with Alternating Bits (Easy) ✨ 📌 Problem Insight A number has alternating bits if every adjacent bit in its binary representation is different. Examples: • 5 → 101 ✅ • 7 → 111 ❌ • 11 → 1011 ❌ We need to check whether a given integer satisfies this condition. 🔍 Approach Use bit manipulation: 1️⃣ Store last bit using n & 1 2️⃣ Right shift the number (n >> 1) 3️⃣ Compare current bit with previous bit 4️⃣ If two adjacent bits are same → return false 5️⃣ If loop finishes → return true We process bit by bit until the number becomes 0. 💡 Why This Works • We directly compare adjacent bits • No extra space needed • Simple and interview-friendly • Efficient binary traversal ⏱ Complexity Time: O(log n) (number of bits) Space: O(1) 🧠 Pattern Bit Manipulation | Bitwise AND | Right Shift Even simple problems strengthen bit fundamentals. Small logic. Clean implementation. Strong basics. 🚀 Consistency over motivation — one problem a day 🔥 #LeetCode #DSA #BitManipulation #Cplusplus #CodingDaily #Consistency
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development