Day 51: Tackling the "Hard" 🧠 Problem 761: Special Binary String After a streak of "easy"s, the difficulty spiked. This one was essentially a parentheses-balancing problem disguised as binary. The Strategy: • Identify: Tracked "Special" substrings using a balance counter. • Recurse: Processed inner strings recursively to find their best forms. • Sort: Reverse-sorted the resulting components to maximize the value. Ngl, I needed a hand with the implementation, but the logic—treating binary strings like nested structures—finally clicked. Sometimes you have to get cooked to learn. 🧗♂️ #LeetCode #Java #Recursion #Algorithms #ProblemSolving #DailyCode
Binary String Problem Solving with Recursion
More Relevant Posts
-
Day 56: Bit-Heavy Sorting 🔢 Problem 1356: Sort Integers by The Number of 1 Bits The mission: Sort an array based on the number of set bits (1s). If there’s a tie, the smaller number wins. The Strategy: • Custom Sort: Swapped a standard sort for a bit-count comparison. • Tie-Breaking: Used Integer.bitCount() to compare 1s, then fell back to raw values if counts were equal. • Bubble Logic: Implemented a nested loop to bubble the "heavier" bit counts to the end. Is O(n²) the fastest way? Definitely not. Does it get the green checkmark for today? Absolutely. Sometimes simple logic just hits different. 🚀 #LeetCode #Java #BitManipulation #Algorithms #Coding #DailyCode
To view or add a comment, sign in
-
-
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
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 57: Binary Breakdown ⚡ Problem 1404: Number of Steps to Reduce a Number in Binary Representation to One Today’s challenge: Divide by 2 if even, add 1 if odd. Repeat until you hit 1. The Strategy: • The Trap: Initially tried Integer.parseInt(), but the test cases hit me with strings longer than Integer.MAX_VALUE. Absolute poverty. 💀 • The Pivot: Switched to a single-pass traversal from right to left, tracking the carry. • Logic: If a bit + carry equals 1, it's an odd number, requiring 2 steps (add 1, then divide) and generating a new carry. Otherwise, it's just 1 step to divide. Moving from O(N) string conversions to a lean O(N) bit-by-bit logic. Big integers can't stop the streak. 🚀 #LeetCode #Java #BitManipulation #Algorithms #ProblemSolving #DailyCode
To view or add a comment, sign in
-
-
𝗧𝗼𝗱𝗮𝘆’𝘀 𝗶𝗻𝘁𝗲𝗿𝗲𝘀𝘁𝗶𝗻𝗴 𝗽𝗿𝗼𝗯𝗹𝗲𝗺: LeetCode 1980 – Find Unique Binary String Given n unique binary strings of length n, the task is to construct a binary string that does not exist in the list. The brute-force idea would explore up to (2^n) possibilities. But there’s a much cleaner insight: if we flip the i-th bit of the i-th string and build a new string from those flips, the result is guaranteed to differ from every string in the list. This technique comes from 𝗖𝗮𝗻𝘁𝗼𝗿’𝘀 𝗱𝗶𝗮𝗴𝗼𝗻𝗮𝗹 𝗮𝗿𝗴𝘂𝗺𝗲𝗻𝘁, a concept from mathematics that turns out to be surprisingly useful in algorithm design. Always enjoyable when a simple idea leads to an optimal 𝗢(𝗻) solution. #leetcode #algorithms #datastructures #problemSolving #softwareengineering #java
To view or add a comment, sign in
-
-
Day 16 of Daily DSA 🚀 Solved LeetCode 75: Sort Colors ✅ Approach: Used the Dutch National Flag algorithm with three pointers. start → tracks position for 0s mid → current element end → tracks position for 2s By swapping elements in-place, the array is sorted in one pass without using any built-in sort. ⏱ Complexity: • Time: O(n) — single traversal • Space: O(1) — in-place sorting 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.63 MB (Beats 42.09%) A classic problem that perfectly demonstrates pointer-based thinking. #DSA #LeetCode #Java #BinarySearch #TwoPointers #ProblemSolving #DailyCoding #Consistency
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
-
-
#Day54 of my second #100DaysOfCode Today’s problem was all about prefix sums and pattern recognition. DSA • Solved Largest Subarray with Sum 0 (GFG) • Started with brute force by checking all subarrays → O(n²) time • Moved to a better approach using prefix sum • Implemented the optimal solution using HashMap to store first occurrence of prefix sums → O(n) time, O(n) space • Key insight: if the same prefix sum appears twice, the elements in between sum to zero This one really strengthened my understanding of prefix sums and how hashing can reduce quadratic problems to linear time. Slow progress, strong foundations. #DSA #Algorithms #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
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 14 of Daily DSA 🚀 Solved LeetCode 153: Find Minimum in Rotated Sorted Array ✅ Approach: Used Binary Search to locate the minimum element in a rotated sorted array. At each step, compared nums[mid] with nums[end] to determine which half is unsorted and contains the minimum. By shrinking the search space intelligently, the minimum element is found efficiently. A great example of how Binary Search adapts to rotated arrays. ⏱ Complexity: • Time: O(log n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.66 MB (Beats 87.66%) Binary Search mastery keeps leveling up 💪 #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
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