Day 62: Recursive Patterns 🌀 Problem 1545: Find Kth Bit in Nth Binary String Today was all about string evolution. The task: generate a sequence where each string is formed by taking the previous one, adding a "1", and then appending the reversed and inverted version of the previous string. I took the simulation route for this one. I used a StringBuilder to progressively build the sequence up to N. In each step, I captured the previous state, reversed it, flipped the bits, and glued it all together. It’s a literal implementation of the problem's rules that makes the growth of the string easy to visualize. The brute force simulation worked, but with the string length doubling every iteration (2ⁿ − 1), it definitely tests the limits of heap memory for larger N. It’s a great reminder that while building the whole string is satisfying, there’s usually a hidden recursive logic that can find the answer without storing the entire sequence. We keep moving! 🚀 #LeetCode #Java #StringManipulation #CodingChallenge #ProblemSolving #DailyCode
Kth Bit in Nth Binary String LeetCode Challenge
More Relevant Posts
-
Day 56/100 | #100DaysOfDSA 🧠⚡ Today’s problem: String Compression A clean in-place array manipulation problem. Core idea: Compress consecutive repeating characters and store the result in the same array. Approach: • Traverse the array using a pointer • Count consecutive occurrences of each character • Write the character to the array • If count > 1 → write its digits one by one • Move forward and repeat Key insight: We don’t need extra space — just carefully manage read & write pointers. Time Complexity: O(n) Space Complexity: O(1) Big takeaway: In-place algorithms require precise pointer control but give optimal space efficiency. Mastering these improves real-world memory optimization skills. 🔥 Day 56 done. #100DaysOfCode #LeetCode #DSA #Algorithms #Strings #TwoPointers #InPlace #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
🚀 DSA Practice – Longest Subarray with Sum = K (Positive Numbers) Today I practiced a classic Sliding Window / Two Pointer problem. Problem: Find the longest subarray whose sum equals K, when the array contains only positive numbers. 💡 Key Idea: * Since all numbers are positive, we can use the sliding window technique: Expand the window by moving the right pointer. * If the sum becomes greater than k, shrink the window using the left pointer. Whenever sum == k, update the maximum length. ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(1) Example: arr = [1, 2, 3, 1, 1, 1, 1, 4, 2, 3] k = 3 Longest subarray: [1, 1, 1] Length = 3 This problem is a great example of how understanding constraints (positive numbers) allows us to replace complex approaches like HashMap + Prefix Sum with a simpler and more efficient Sliding Window technique. #DSA #Algorithms #Java #SlidingWindow #LeetCode #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 51/100 | #100DaysOfDSA 🚀⚡ Today’s problem: Product of Array Except Self Given an array, return a new array where each element is the product of all elements except itself — without using division. Brute force? Too slow. Division? Not allowed. Optimized Approach: • Build prefix product array (left to right) • Then multiply with suffix product (right to left) • No extra space needed (excluding output) Time Complexity: O(n) Space Complexity: O(1) Big takeaway: Breaking a problem into prefix + suffix patterns can unlock optimal solutions. Clean logic. Efficient approach. 💯 Day 51 done. 🔥 #100DaysOfCode #LeetCode #DSA #Algorithms #Arrays #PrefixSum #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 82/100 – LeetCode Challenge ✅ Problem: #43 Multiply Strings Difficulty: Medium Language: Java Approach: Manual Multiplication with Result Array Time Complexity: O(n × m) Space Complexity: O(n + m) Key Insight: Multiply digits from right to left (least significant first). Store intermediate results in array where index i + j + 1 holds current digit. Handle carry by adding to previous index. Solution Brief: Edge case: if either number is "0", return "0". Created result array of size n1 + n2 (max possible digits). Nested loops multiply each digit of num1 with each digit of num2. Accumulated results with proper carry handling. Built final string skipping leading zeros. #LeetCode #Day82 #100DaysOfCode #Math #String #Java #Algorithm #CodingChallenge #ProblemSolving #MultiplyStrings #MediumProblem #Multiplication #Array #DSA
To view or add a comment, sign in
-
-
Day 16/100 – LeetCode Challenge Problem Solved: Binary Tree Level Order Traversal Today’s problem focused on traversing a binary tree level by level. Instead of visiting nodes in depth-first order, the goal is to group nodes according to their depth in the tree. The idea behind the solution is to track the level of each node while traversing the tree. Starting from the root at level 0, each recursive call increases the level for its child nodes. When visiting a node, we check whether a list for that level already exists. If not, we create one; otherwise, we append the node value to the existing level list. By doing this, the traversal naturally organizes nodes into separate lists representing each level of the tree. Time Complexity: O(n) Space Complexity: O(n) Key takeaway: Tree problems often become easier when you track additional context during traversal. In this case, maintaining the current level allows the recursion to build a structured level-by-level result. Day 16 completed. Continuing the consistency streak and strengthening tree traversal concepts. #100DaysOfLeetCode #Java #BinaryTree #TreeTraversal #Algorithms #ProblemSolving
To view or add a comment, sign in
-
-
Day 64: The Art of Alternating 🏁 Problem 1758: Minimum Changes To Make Alternating Binary String Today was about finding the shortest path to a perfect pattern. The goal: transform a binary string into an alternating sequence (0101... or 1010...) with the minimum number of flips. The Strategy: • Pattern Prep: Recognized that only two target patterns exist for any given length. • The Comparison: Pre-generated both ideal patterns and ran a head-to-head comparison against the original string. • The Result: Counted the mismatches for both scenarios and returned the minimum. Ngl, generating two full arrays just to compare bits is a bit of a memory flex, but it makes the logic crystal clear. Sometimes visualizing the "perfect" state is the easiest way to fix the current one. 🚀 #LeetCode #Java #StringManipulation #Algorithms #ProblemSolving #DailyCode
To view or add a comment, sign in
-
-
Day 33/75 — Sort an Array (Merge Sort) Today’s problem required sorting an array in O(n log n) time without using built-in sort. Approach: • Divide array into two halves • Recursively sort both halves • Merge sorted halves Key idea: return merge(left, right); Merge step ensures elements are placed in sorted order. Time Complexity: O(n log n) Space Complexity: O(n) This problem reinforced the concept of Divide & Conquer. 33/75 🚀 #Day33 #DSA #MergeSort #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
Day 33 of Daily DSA 🚀 Solved LeetCode 58: Length of Last Word ✅ Problem: Given a string s, return the length of the last word (a sequence of non-space characters). Approach: First, trim() the string to remove trailing spaces Traverse the string from the end Count characters until a space is encountered 💡 Key Insight: Instead of splitting the string (which uses extra space), we can simply iterate backwards for an efficient solution. ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.17 MB A simple yet important problem to strengthen string traversal techniques. #DSA #LeetCode #Java #Strings #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 43/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Search a 2D Matrix II Interesting matrix pattern here. Matrix properties: • Each row is sorted left → right • Each column is sorted top → bottom Key idea: Start from the top-right corner. Why? • If current value > target → move left • If current value < target → move down This way we eliminate one row or column every step. Time Complexity: O(m + n) Space Complexity: O(1) Big takeaway: Choosing the right starting point can simplify the entire search. Matrix patterns getting stronger day by day. 🔥 Day 43 done. #100DaysOfCode #LeetCode #DSA #Algorithms #Matrix #BinarySearch #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
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