Leetcode POTD : Minimum ASCII Delete Sum of Two Strings Here, we need to delete minimum ASCII valued characters to make two strings equal. Intuition : 🤔 We want both strings to become the same, so we start with two pointers. If characters at both indices are equal → no deletion needed, just move ahead ✅ If characters are different, then we must delete, but the confusion is 🤯 👉 should we delete from s1 or from s2 to get the minimum cost? So we can try both options: delete from s1 delete from s2 This clearly points towards recursion 🔁 While solving recursively till the end of both strings, if you draw the recursion tree (yes, I did ✍️), you’ll notice overlapping subproblems. So why recompute? 🤷♂️ That’s where DP + memoization comes in We store results and optimize the solution efficiently. Attaching my thought process diagram below 👇 #Leetcode #POTD #DynamicProgramming #Recursion #DP #CodingJourney #programming
Leetcode POTD: Minimum ASCII Delete Sum of Two Strings
More Relevant Posts
-
Day 13 of #100DaysOfCode – C# Today I built a small text summariser method in C#. The method takes a long sentence and trims it down to a shorter version based on a maximum length. What I learned today: Writing and calling my own methods with parameters and return values (e.g. SummarizeText(string text, int maxLength = 20)) Using string operations like Length, Split, and loops to construct a result step by step How default parameter values work, allowing methods to be called with or without optional arguments This exercise reinforced how methods help encapsulate logic, improve reusability, and keep code clean skills that become increasingly important as projects grow beyond simple, single-file programs. On to Day 14. #CSharp #DotNet #100DaysOfCode #Programming #LearningToCode #Methods #Strings
To view or add a comment, sign in
-
-
🚀 LeetCode POTD — 712. Minimum ASCII Delete Sum for Two Strings Solved | Medium | Dynamic Programming | Strings 🔗 Solution Link: https://lnkd.in/gT_c_eJ8 This is a classic DP on strings problem, similar to LCS-style thinking. Approach: Use recursion + memoization with two pointers i and j: If s1[i] == s2[j] → move both pointers. Else → try: delete s1[i] delete s2[j] and take the minimum ASCII cost of both choices. Base cases handle when one string is exhausted (sum remaining ASCII values of the other). 📈 Complexity: Time: O(n × m) Space: O(n × m) #LeetCode #ProblemOfTheDay #DynamicProgramming #StringDP #DSA #CodingJourney #Consistency #Programming
To view or add a comment, sign in
-
-
LeetCode Today’s Question : Check If String Is a Prefix of Array 🔢 LeetCode #: 1961 🧠 Approach Used: Progressive String Concatenation ⏱ Time Complexity: O(n · m) (n = number of words, m = avg word length) 💾 Space Complexity: O(1) (excluding input storage) 📌 What I learned today: Building the string step-by-step makes prefix checks straightforward Early termination saves unnecessary computation Simple logic often beats overthinking on easy problems Consistency > speed when learning DSA Slow and steady DSA progress 🚀💻 #LeetCode #DSA #DataStructures #Algorithms #ProblemSolving #CodingJourney #Cplusplus #Programming #SoftwareEngineering #Placements #Consistency #DailyCoding #TechLife
To view or add a comment, sign in
-
-
🗓 Day 87 / 100 – #100DaysOfLeetCode 📌 Problem 44: Wildcard Matching Today’s problem was a classic dynamic programming challenge involving string pattern matching. The task was to determine whether a string matches a pattern containing: ? → matches any single character * → matches any sequence of characters (including empty) 🧠 My Approach: Used Dynamic Programming where: dp[i][j] represents whether the first i characters of the string match the first j characters of the pattern Handled base cases carefully: Empty string vs pattern Patterns starting with * Transition rules: If characters match or pattern has ? → inherit diagonal state If pattern has * → either: match zero characters or match one/more characters Final answer comes from dp[n][m]. This approach ensures all wildcard possibilities are handled correctly. 💡 Key Learning: This problem reinforced: ✔ thinking in terms of states and transitions ✔ handling multiple matching paths with DP ✔ importance of correct base-case initialization Wildcard matching problems are great practice for mastering string DP patterns. Day 87 done — almost at the finish line 🚀 #100DaysOfLeetCode #LeetCodeChallenge #ProblemSolving #DynamicProgramming #StringMatching #DP #Algorithms #DSA #CompetitiveProgramming #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
📘 Problem Solving Update – Today’s Practice Had a productive session solving two solid problems focused on sliding window and dynamic programming. ✅ GFG POTD – Substrings with K Distinct Characters Approach: Used the classic “at most K” sliding window technique. The idea is to count substrings with at most K distinct characters and subtract substrings with at most (K−1) distinct characters. This converts the problem into an efficient linear-time solution using two pointers and a frequency tracker, instead of brute force. Key learnings: Two pointer window expansion and contraction Frequency tracking for distinct characters Turning an “exactly K” problem into a difference of two simpler problems ✅ LeetCode Daily – Minimum ASCII Delete Sum for Two Strings Approach: Solved using Dynamic Programming with Space Optimization. The goal is to make both strings equal by deleting characters with minimum ASCII cost. Defined DP states based on suffixes of the strings, where each state represents the minimum cost needed from that point onward. Optimized from 2D DP to 1D using only previous and current rows. Key learnings: DP on strings Transition based on character match vs delete choices Space optimization without losing clarity Consistent practice, deeper understanding. On to the next one 🚀 #ProblemSolving #DSA #LeetCode #GeeksForGeeks
To view or add a comment, sign in
-
String Immutability My Turning Point My first real introduction to the power of string immutability came with a multi-threaded application. I had to deal with strings shared between multiple threads, and if they had changed unexpectedly, it could have led to code chaos. Immutability made sure that data was consistent, no matter how many threads were accessing the same information. This first hand experience showed me how immutability could save my programming efforts from disaster. What It Taught Me After that, I became more aware of the following: -Safety matters: String immutability provides confidence that sensitive strings, like passwords or file paths, will remain the same. -Performance isn’t always obvious: Immutability allows certain programming languages to optimize memory usage. -Predictability is priceless: The biggest benefit I encountered when adopting immutability was error debugging got easier. #Programming #CSharp #CodingTips #Immutability #MyCodingJourney
To view or add a comment, sign in
-
-
🚀 LeetCode 3634: Minimum Removals to Balance Array Difficulty: Medium Today’s problem was a clean example of how sorting + two pointers can simplify what looks like a tricky condition-based removal problem. 🧩 Problem Summary We are given an array nums and an integer k. The array is balanced if: [ max \le k \times min ] We can remove any number of elements (but not all). Goal: minimum removals to make the remaining array balanced. 💡 Key Insight Instead of thinking about removing elements, think about: ✅ keeping the largest valid subset If we sort the array, then for any valid window [l...r]: min = nums[l] max = nums[r] Condition becomes: [ nums[r] \le nums[l] \times k ] So the problem reduces to finding the longest subarray window satisfying this. ⚡ Approach (Two Pointers / Sliding Window) Sort the array Use pointers l and r Expand r If condition breaks, move l Track maximum window length Final Answer: [ removals = n - maxWindowLength ] ⏱ Complexity Sorting: O(n log n) Sliding Window: O(n) Total: O(n log n) Extra Space: O(1) 🔥 Takeaway Sometimes the fastest way to solve a “minimum removals” problem is to find the maximum elements you can keep. #leetcode #dsa #cpp #twopointers #slidingwindow #sorting #coding #LearningInPublic #programming #competitiveprogramming
To view or add a comment, sign in
-
-
Variables, data types, if statements, loops. Get these right and C# clicks. Most people skip syntax fundamentals and wonder why advanced tutorials confuse them. You can't understand classes if you don't understand variables. This playlist covers the essential syntax building blocks that everything else depends on. Once you nail these, the rest becomes logical. Start here: https://lnkd.in/ebft3icT #CSharp #Programming #Fundamentals
To view or add a comment, sign in
-
Day 8 of #100DaysOfCode with C# Today I reviewed the core primitive types and expressions in C#, which are the building blocks of every program Key takeaways: Primitive types like int, byte, float, double, char, and bool each have specific ranges and uses, so choosing the right one matters for memory and correctness. I practised arithmetic, comparison, and logical operators, and saw how C# follows operator precedence (for example, multiplication before addition) unless I use parentheses. I also revised how implicit and explicit conversions work between numeric types and why casting is sometimes required to avoid data loss. Understanding these basics makes later topics like methods, classes, and collections much easier because everything is built on top of these simple values and expressions. #CSharp #DotNet #100DaysOfCode #Programming #PrimitiveTypes #Expressions
To view or add a comment, sign in
-
*** Problem of the Day: Minimum Deletions to Make String Balanced One of the classic DP problems I recently solved. The goal Given a string containing only 'a' and 'b', remove the minimum number of characters so that all 'a's appear before all 'b's. 🔹 Approach I used (DP + Greedy logic): 1. Traverse the string recursively. 2. Keep track of 'b's seen so far (cntb). 3. For each character: 1. If 'a' appears after some 'b', delete it. 2. If 'b' appears before any 'b', either delete it or count it for future comparison. 4. Use memoization to avoid recomputation. Check out my solution here!👇 https://lnkd.in/gcVFdHei The solution essentially decides greedily whether to delete 'a' or 'b' at each step to minimize total deletions. A classic example where DP meets greedy thinking. #Coding #Programming #DataStructures #Algorithms #DynamicProgramming #DP #GreedyAlgorithms #ProblemSolving #LeetCode #CompetitiveProgramming #Tech #SoftwareEngineering #CodeDaily #LearningToCode #CodingChallenge #CodeOptimization #AlgorithmDesign #LinkedInLearning
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