Day 9 | Round 5 — 30 Days Coding Challenge 🚀 Today I solved the problem “Find K-th Bit in N-th Binary String.” 🔎 Problem (In Simple Words) We are given two numbers n and k. A binary string is built using this rule: S1 = "0" Si = S(i-1) + "1" + reverse(invert(S(i-1))) We need to find the k-th bit in the string Sn. 💡 Understanding the Pattern Each new string is built using three parts: Previous string The character "1" The reversed and inverted version of the previous string Invert means: Change 0 → 1 Change 1 → 0 So every level depends completely on the previous level. 🛠️ Approach I Used Start with base case: S1 = "0" For each level from 2 to n: Invert the previous string Reverse it Concatenate: previous + "1" + reversed inverted string Finally, return the (k-1) index from Sn This directly follows the pattern defined in the problem. ⚙️ Complexity Time Complexity: Exponential string growth (since length doubles each level) Space Complexity: Stores all generated strings This problem helped me understand: Recursive string construction patterns String manipulation (reverse + invert) How problems build on previously generated results Round 5 — Day 9 Completed ✅ Recognizing patterns in construction-based problems makes implementation much clearer. #30DaysOfCode #Round5 #Day9 #StringManipulation #RecursionPattern #DSA #ProblemSolving #LeetCode #CodingChallenge #CPlusPlus #DeveloperJourney #Consistency #CodeDaily #TechGrowth
Kth Bit in Nth Binary String Problem Solution
More Relevant Posts
-
🚀 Day 526 of #750DaysOfCode 🚀 Today I solved LeetCode 3129 – Find All Possible Stable Binary Arrays I. 🔹 Problem Summary We are given three integers: zero, one, and limit. We need to count the number of binary arrays that: • Contain exactly zero number of 0s • Contain exactly one number of 1s • Do not allow more than limit consecutive identical elements In other words, every subarray longer than limit must contain both 0 and 1, preventing long runs of the same digit. 🔹 Approach I solved this using Dynamic Programming. Idea: Track how many zeros and ones are used. Maintain the last placed digit (0 or 1). Ensure the count of consecutive digits never exceeds the limit. Use DP states to count valid configurations and apply modulo (10^9 + 7) for large results. 🔹 Key Concepts Practiced Dynamic Programming State transitions Handling constraints with limit on consecutive elements Modular arithmetic 💡 Problems like this strengthen DP intuition and constraint handling, which are very common in coding interviews. Consistency continues… 🔥 #leetcode #dsa #dynamicprogramming #codingchallenge #softwareengineering #programming #developers #learninginpublic #techjourney #750daysofcode
To view or add a comment, sign in
-
-
🔥 #19 Day of my Leetcode Streak. Consistency is slowly turning into real progress. Today I solved Problem #344 – Reverse String using C++ on LeetCode. What makes today interesting is that I also started my String topic practice, and this was the first problem I solved after understanding the theory behind strings. 📌 Quick Insight – What is a String in C++? A string is simply a sequence of characters used to represent text. In this problem, the string is given as a character array (vector<char>), and the challenge is to reverse it in-place without using extra memory. 💡 Approaches I explored while solving this: 1️⃣ Two Pointer Technique I placed one pointer at the start and another at the end of the array. By swapping the characters and gradually moving both pointers toward the center, the string gets reversed efficiently. This approach helped me understand the internal logic behind how reversal works. 2️⃣ Using the STL Inbuilt Function C++ also provides a direct and elegant solution using: reverse(s.begin(), s.end()); This single line reverses the entire container using the STL reverse algorithm. Moments like these remind me that DSA is not just about solving problems, but about understanding multiple ways to think about a solution. On to the next challenge. 🚀 #LeetCode #19DayStreak #DSAJourney #ProblemSolving #CppProgramming #CodingJourney #LearningInPublic #BuildInPublic #FutureSDE #SoftwareEngineering #DeveloperJourney #ConsistencyMatters #TechGrowth #PlacementPreparation
To view or add a comment, sign in
-
-
🔥 Daily Coding Challenge Special Positions in a Binary Matrix Today’s challenge: Given a binary matrix, find all special positions positions with 1 where all other elements in the same row and column are 0. 💡 Approach: ✅ Traverse each cell. ✅ For every 1, check its row & column. ✅ If no other 1s exist, it’s a special position → count it. 🧩 Key Takeaway: Matrix traversal + logical checks can solve interesting problems efficiently. 📌 Try it yourself: Can you optimize it further using row & column counts? #DailyChallenge #Coding #LeetCode #ProblemSolving #CPlusPlus
To view or add a comment, sign in
-
-
🚀 Day 27/60 — LeetCode Discipline Problem Solved: Length of Last Word Difficulty: Easy Today’s problem looked simple, yet it emphasized a subtle but important skill — handling edge cases cleanly. The goal was to find the length of the last word in a string, ignoring any trailing spaces. Instead of splitting the string or using extra space, the solution efficiently traverses from the end, skipping unnecessary characters and counting only what truly matters. It’s a reminder that strong coding is not always about complexity — sometimes, it’s about precision and clarity in small details. 💡 Focus Areas: • Practiced string traversal from end • Improved handling of trailing spaces • Reinforced clean and efficient logic • Avoided unnecessary extra space usage • Strengthened edge-case thinking ⚡ Performance Highlight: Achieved 0 ms runtime (100% performance). Small problems, when approached with discipline, sharpen the instincts that solve big ones. #LeetCode #60DaysOfCode #100DaysOfCode #DSA #Strings #Algorithms #ProblemSolving #CodingJourney #SoftwareEngineering #Java #Developers #Consistency #TechJourney #LearnToCode
To view or add a comment, sign in
-
-
🚀 Day 6 of 100 Days LeetCode Challenge Problem: Check if Binary String Has at Most One Segment of Ones Today’s problem is all about pattern observation in strings—simple, but easy to overthink. 💡 Key Insight: The string should contain only one continuous block of '1's. 👉 That means: Once a 0 appears after a 1, There should be no more '1's later 🔍 Simplest Trick: Just check if the pattern "01" appears more than once OR even better → check if "10" appears followed by another "1" 💡 Cleaner approach: Traverse the string Count transitions from 1 → 0 If you ever see 1 again after that → ❌ Invalid 🔥 What I Learned Today: Many problems are just pattern validation Clean logic beats complex conditions Always try to reduce the problem to a simple rule 📈 Challenge Progress: Day 6/100 ✅ Consistency building strong! LeetCode, Strings, Pattern Recognition, Greedy, DSA Practice, Coding Challenge, Problem Solving, Algorithm Thinking, Programming #100DaysOfCode #LeetCode #DSA #CodingChallenge #Strings #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 13 of My Coding Journey Today I worked on an interesting problem: 527 Valid Word Abbreviation 💡 👉 The challenge was to check whether a given abbreviation correctly represents a word. It involved handling: Character matching ✅ Skipping characters using numbers 🔢 Edge cases like leading zeros ❌ 💻 Key Logic I Used: Two pointers (i for word, j for abbreviation) If characters match → move both pointers If digit found → build number and skip characters in word If invalid case → return false ✨ Code Snippet: class Solution { public: bool validWordAbbreviation(string word, string abbr) { int i=0, j=0; while(i<word.size() && j<abbr.size()) { if(abbr[j]=='0') return false; if(word[i]==abbr[j]) { i++; j++; } else if(isalpha(abbr[j])) return false; else { int num=0; while(j<abbr.size() && isdigit(abbr[j])) { num = (num*10) + (abbr[j]-'0'); j++; } i += num; } } return i==word.size() && j==abbr.size(); } }; 🧠 What I Learned: How to efficiently parse strings with mixed characters & numbers Importance of handling edge cases like "01" ❗ Two-pointer technique is 🔥 for string problems 📌 Consistency > Perfection See you tomorrow with Day 14! 💪 #100DaysOfCode #DSA #Cpp #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 10 of 100 Days LeetCode Challenge Problem: Find All Possible Stable Binary Arrays II Today’s problem is an extension of Day 9—but with optimized Dynamic Programming ⚡ 💡 Key Insight: Same constraints: Fixed number of 0s and 1s No more than limit consecutive identical elements 👉 Which means: We must carefully control streak length And efficiently count all valid combinations 🔍 Approach (Optimized DP): Use DP + Prefix Sum Optimization State includes: Count of 0s used Count of 1s used Ending with 0 or 1 💡 Optimization: Instead of recalculating ranges repeatedly, use prefix sums This reduces time complexity significantly 👉 Apply modulo (10⁹ + 7) for large answers 🔥 What I Learned Today: Same problem can have multiple levels of optimization Prefix sum is powerful in reducing DP transitions Moving from brute → DP → optimized DP is real growth 📈 📈 Challenge Progress: Day 10/100 ✅ Double digits achieved! LeetCode, Dynamic Programming, Prefix Sum, Optimization, Combinatorics, Binary Arrays, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #DynamicProgramming #PrefixSum #Optimization #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
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
-
-
Ever stared at your own code a month later and wondered, "What was I thinking?!" 😵💫 We've all been there! One of the quickest wins for cleaner, more maintainable code is embracing **meaningful and descriptive variable names**. ✨ Instead of using vague names like `x`, `data`, or `temp`, think about what the variable *represents* in your specific context. This makes your code self-documenting, easier to debug, and a joy for your future self (and your teammates!) to read. Take a look at the difference: ```python # Before (unclear purpose) def calc(x, y): return x * y # After (crystal clear!) def calculate_rectangle_area(length, width): return length * width ``` See how much easier it is to understand the "After" example's intent without any extra comments? That's the power of good naming! What's YOUR favorite clean code practice that changed your development life? Share your wisdom below! 👇 #CleanCode #ProgrammingTips #SoftwareDevelopment #DevTips #CodingBestPractices #CodeQuality #DeveloperLife #TechEd
To view or add a comment, sign in
-
-
Day 6 of My LeetCode Consistency Journey Today I solved Longest Consecutive Sequence (LeetCode 128). At first, my instinct was to sort the array and then check for consecutive elements. But sorting leads to O(n log n) time complexity, while the problem expects an O(n) solution. After thinking through it, I realized the key idea is to use hashing. 💡 Main insight: A number should only start a sequence if (num - 1) does not exist. This ensures we only start counting from the beginning of a sequence and avoid unnecessary checks. From there, the sequence can be expanded using num + 1 until the chain breaks. Key learnings from today: • Using a hash set for O(1) lookup can drastically improve performance. • Identifying the start of a sequence avoids redundant computation. • Small implementation details matter — like not modifying the loop variable during iteration. This problem was a great reminder that sometimes the real challenge is recognizing the pattern, not writing the code. Day by day, the goal remains the same: consistency and better problem-solving thinking. #LeetCode #DSA #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
More from this author
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