Kth Bit in Nth Binary String Problem Solution

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

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories