🚀 Day 2/365 – Interleaving String (LeetCode 97) Today’s challenge was a classic Dynamic Programming problem – Interleaving String. 🔎 Problem Statement: Given three strings s1, s2, and s3, determine whether s3 is formed by interleaving s1 and s2 while maintaining the relative order of characters. 🧠 Key Learning At first glance, it looks like a simple string problem. But the real insight was realizing this is a 2D DP grid problem. If: len(s1) + len(s2) != len(s3) 👉 It’s immediately false. Then we build a DP table where: dp[i][j] = whether first i chars of s1 and first j chars of s2 can form first i + j chars of s3. This problem strengthened my understanding of: ✔️ State definition in DP ✔️ Transition logic ✔️ Space optimization (2D → 1D) ✔️ Thinking in terms of grid movement (down = s1, right = s2) 💡 Big Takeaway Most string problems are actually: 👉 Hidden Dynamic Programming 👉 About defining the correct state Consistency > Motivation. On to Day 3 💪 #365DaysOfCode #LeetCode #DynamicProgramming #Java #ProblemSolving #CodingJourney
Interleaving String Problem Solving with Dynamic Programming
More Relevant Posts
-
🚀 Day 88 of 100 Days of LeetCode Problem: Min Cost Climbing Stairs Difficulty: Easy Today’s problem was another classic Dynamic Programming pattern. Each step has a cost, and you can climb either 1 or 2 steps at a time. The goal is to reach the top with the minimum total cost. You can start from index 0 or index 1. The key idea: To reach step i, you must come from either i-1 or i-2. So the recurrence becomes: dp[i] = cost[i] + min(dp[i-1], dp[i-2]) Finally, since you can reach the top from the last or second-last step: answer = min(dp[n-1], dp[n-2]) This problem reinforces the “take minimum of previous two states” DP pattern — very similar to Climbing Stairs but focused on cost minimization instead of counting ways. Time Complexity: O(n) Space Complexity: O(n) → can be optimized to O(1) Another solid DP variation completed. On to Day 89 💪 #LeetCode #100DaysOfCode #DSA #DynamicProgramming #Java #Algorithms #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 75/100: LeetCode Challenge - Count and Say 🔢 Today I tackled the "Count and Say" sequence problem - a fascinating exercise in string manipulation and pattern recognition! Problem: The count-and-say sequence starts with "1". Each subsequent term is generated by "saying" the previous term - counting consecutive digits and saying the count followed by the digit. Example: 1 → "one 1" → "11" 11 → "two 1s" → "21" 21 → "one 2, one 1" → "1211" My approach: Started with base case "1" Iteratively built each next term by traversing the current string Counted consecutive identical characters and appended count + digit to StringBuilder Used StringBuilder for efficient string concatenation Results: ✅ Runtime: 3 ms (beats 72.74%) ✅ Memory: 42.90 MB (beats 84.80%) Key takeaway: Sometimes the most straightforward iterative approach is the best! This problem teaches the importance of careful string traversal and StringBuilder usage for optimal performance. The key was recognizing the pattern: each new string is just a "run-length encoding" of the previous one. #100DaysOfCode #LeetCode #Java #StringManipulation #CodingChallenge #ProblemSolving #Day74 #Programming
To view or add a comment, sign in
-
-
🎯 Day 67 of #100DaysOfCode 📌 Problem: Combination Sum Today's challenge was all about finding all unique combinations of candidates where the chosen numbers sum to a given target. The same number can be used unlimited times, and combinations must be unique. 🧠 Approach: Used dynamic programming with a 3D list structure dp[t] stores all combinations that sum to target t Iterated through candidates and built combinations from smaller sums Extended each valid combination by adding current candidate 📊 Stats: ✅ 160/160 test cases passed ⚡ Runtime: 5 ms | Beats 10.10% 💾 Memory: 46.71 MB | Beats 5.88% 📝 Takeaway: This problem highlighted the trade-off between intuitive DP solutions and optimization. While the approach works, there's room for improvement in both runtime and memory efficiency. Backtracking might be a more elegant solution here! 🔗 Problem: Combination Sum 🏷️ #LeetCode #CodingChallenge #Java #DynamicProgramming #Backtracking #Algorithms #TechJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 87 of #100DaysOfCode Solved LeetCode Problem #799 – Champagne Tower 🍾✅ A classic dynamic programming problem that turns a real-world scenario into a clean simulation. Each glass keeps what it can hold and passes the overflow downward — simple idea, elegant execution. Key Takeaways: -> Using 2D DP to simulate flow/overflow -> Handling fractional values with precision -> Bottom-up computation for controlled constraints -> Writing clear logic for visual problems Language: Java -> Runtime: 3 ms (Beats 76.33%) -> Memory: 48.40 MB Consistency builds confidence. One problem, one day. 💻🔥 #LeetCode #Java #DynamicProgramming #Simulation #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
After reading and understanding the question and the test cases for LeetCode 1689 – Partitioning Into Minimum Number of Deci-Binary Numbers, my first thought was to build the sum using deci-binary numbers (0s and 1s) and then count how many numbers are required. That approach felt natural because Example 1 itself explains the solution like this: Input: n = "32" Output: 3 Explanation: 10 + 11 + 11 = 32 So my thinking was to follow the same idea — construct the sum first and then count the numbers. But when I looked at Example 3: Input: n = "27346209830709182346" Output: 9 and noticed the constraint: 1 <= n.length <= 10^5 it became clear that converting the string into numeric types or constructing the sum directly would not scale given the constraints. After carefully going through the hints and the solution, I understood the key insight: Each deci-binary number can contribute only 0 or 1 per digit. So if any digit in the string is 9, we need at least 9 deci-binary numbers to form that digit. Since all digits must be satisfied together, the maximum digit in the string decides the minimum number of deci-binary numbers required. This problem was a good reminder that sometimes the challenge isn’t coding — it’s thinking about constraints the right way. #LeetCode #ProblemSolving #DSA #Learning #Java
To view or add a comment, sign in
-
-
Hi there 👋 Today I want to give you a small glimpse into the future of C++ and honestly, it’s pretty exciting. With static reflection in C++26, we can finally inspect our types and structs at compile time and do things that used to feel like magic in languages like Java or C#. But here’s the real twist: ⚡ No runtime reflection overhead ⚡ Everything happens at compile time ⚡ Zero runtime penalty Yes, compilation might take a little longer… but let’s be honest if you’re already using heavy templates, you’re probably used to that 😅 The power you get in return is incredible. As a small example, I wrote a tiny function that can print almost any struct automatically using our new friend std::meta. Of course, it’s a quick prototype and there are still edge cases I didn’t wrap in it but the idea is clear: 👉 We can inspect types 👉 Iterate over members at compile time 👉 Generate code based on structure And printing structs is just the beginning. If you watched my Python bindings talk at CppCon this year, you might already imagine where this is going… Reflection + C++ bindings = extremely powerful tooling. Think about: automatic bindings serialization schema generation logging / debugging tools meta-driven frameworks The number of possibilities here is huge. Personally, I can’t wait to start using this in production. C++ keeps evolving, and features like this show that the language is still pushing forward in powerful ways. ⚙️ What would YOU build first with C++ static reflection? #cpp #cpp26 #programming #softwareengineering #reflection
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟐𝟎 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on Dynamic Programming 📊 and handling obstacles in grid traversal 🧱. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • 🛣️ Unique Paths II 🔹 𝐔𝐧𝐢𝐪𝐮𝐞 𝐏𝐚𝐭𝐡𝐬 𝐈𝐈 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝟏 – 𝟏𝐃 𝐃𝐏 (𝐒𝐩𝐚𝐜𝐞 𝐎𝐩𝐭𝐢𝐦𝐢𝐳𝐞𝐝) • 📏 Used a single array to store path counts • 🚧 Set dp[j] to 0 whenever an obstacle appears • ➕ Updated paths using left cell value • ⚡ Reduced space complexity from O(m×n) to O(n) 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝟐 – 𝟐𝐃 𝐃𝐏 • 📊 Built a DP table of size m × n • ➕ Each cell = top + left (if not obstacle) • 🚧 Set value to 0 if cell contains obstacle • 📌 Carefully handled first row and column initialization 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • 🧠 DP is about breaking a problem into smaller subproblems • 📊 Grid problems often depend on top and left states • ⚡ Space optimization is possible when only the previous row matters • 🎯 Initialization is critical in DP problems 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • ⏱ Time: O(m × n) • 📦 Space: O(n) (optimized version) 🧠 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Dynamic Programming is not hard — it’s about identifying state transitions correctly. 20 days consistent 🔥 Still moving forward 🚀 #DSA #Arrays #DynamicProgramming #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟓𝟏/𝟑𝟔𝟓 🚀 📌 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐏𝐎𝐓𝐃: 𝐅𝐢𝐧𝐝 𝐀𝐥𝐥 𝐏𝐨𝐬𝐬𝐢𝐛𝐥𝐞 𝐒𝐭𝐚𝐛𝐥𝐞 𝐁𝐢𝐧𝐚𝐫𝐲 𝐀𝐫𝐫𝐚𝐲𝐬 𝐈𝐈 Continuing my 𝟑𝟔𝟓 𝐃𝐚𝐲𝐬 𝐨𝐟 𝐂𝐨𝐝𝐞 journey with a focus on 𝐩𝐫𝐨𝐛𝐥𝐞𝐦-𝐬𝐨𝐥𝐯𝐢𝐧𝐠, 𝐃𝐒𝐀, 𝐚𝐧𝐝 𝐜𝐨𝐧𝐬𝐢𝐬𝐭𝐞𝐧𝐜𝐲. 💪 🔎 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Use Dynamic Programming to track valid arrays using i zeros and j ones while remembering the last placed element. To enforce the limit constraint, subtract invalid configurations that would exceed the allowed consecutive count. 🔍 𝐀𝐥𝐠𝐨𝐫𝐢𝐭𝐡𝐦 𝐮𝐬𝐞𝐝: Dynamic Programming with constraint handling using prefix subtraction. ⏱ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐳𝐞𝐫𝐨 × 𝐨𝐧𝐞) 🧠 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐳𝐞𝐫𝐨 × 𝐨𝐧𝐞) 📈 𝐊𝐞𝐲 𝐭𝐚𝐤𝐞𝐚𝐰𝐚𝐲: When counting valid sequences under constraints, DP combined with invalid-state subtraction efficiently enforces limits. #LeetCode #LeetCodeDaily #365DaysOfCode #DSA #Java #DynamicProgramming #ProblemSolving #LearningInPublic 👨💻 🔗 Problem link in comments 👇
To view or add a comment, sign in
-
-
Day 11/100 Day Coding Challenge Today, I solved the LeetCode problem: Container With Most Water using Java. Here’s a detailed breakdown of my approach and learning: Problem Statement: Given an array of non-negative integers representing heights of vertical lines on a coordinate plane, find two lines that, along with the x-axis, form a container that holds the maximum water. Challenges: A brute-force approach would check all possible pairs of lines (O(n²)), which is inefficient for large arrays. I aimed for an optimized solution using the two-pointer technique. Approach (Two-Pointer Technique): Initialize two pointers: l at the start, r at the end of the array. Compute the current area: curWater = (r - l) * min(height[l], height[r]). Update maximum area found so far. Move the pointer pointing to the shorter line inward: If height[l] < height[r], increment l. Else, decrement r. Repeat until the pointers meet. #100DaysOfCode #Java #LeetCode #TwoPointerTechnique #ProblemSolving #Algorithms #SoftwareEngineering #Day11
To view or add a comment, sign in
-
-
Day 8/100 – LeetCode Challenge Problem: Trapping Rain Water Today’s problem focused on using the two-pointer technique to calculate how much water can be trapped between elevation bars. Approach: Use two pointers: left and right Maintain two variables: leftMax and rightMax Move the pointer with the smaller height Calculate trapped water using the difference between the current height and the maximum boundary Key Idea: Water trapped at any position depends on the minimum of the maximum heights on both sides. If height[left] < height[right] → process the left side Otherwise → process the right side Complexity: Time: O(n) Space: O(1) Concepts Practiced: Two-pointer technique Greedy decision making Array traversal optimization #100DaysOfCode #LeetCode #DSA #Java #TwoPointers #ProblemSolving #CodingJourney
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