📅 Day 64 of #100DaysOfLeetCode 🧮 Problem: 712. Minimum ASCII Delete Sum for Two Strings Difficulty: Medium 🧠 Key Idea The problem is a Dynamic Programming on strings variant, similar to Edit Distance. Instead of minimizing operations, we minimize the sum of ASCII values of deleted characters to make both strings equal. We compare prefixes of both strings and decide whether to: keep matching characters, or delete a character from either string with minimum cost. ✅ Approach (Bottom-Up DP / Tabulation) State Definition: dp[i][j] → Minimum ASCII delete sum to make s1[0…i-1] and s2[0…j-1] equal. 🔹 Step 1: Base Cases If s2 is empty → delete all characters of s1 If s1 is empty → delete all characters of s2 🔹 Step 2: DP Transition If characters match → no deletion needed Else → choose the cheaper delete: delete from s1 delete from s2 🔹 Final Answer Stored in dp[n][m] ⏱ Complexity Time: O(n × m) Space: O(n × m) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
Minimize ASCII Delete Sum for Two Strings with Dynamic Programming
More Relevant Posts
-
🚀 Day 52 of #100DaysOfCode Solved LeetCode Problem #712 – Minimum ASCII Delete Sum for Two Strings. This problem focused on minimizing the total ASCII value of deleted characters to make two strings equal. A classic dynamic programming challenge that required carefully defining states and transitions for optimal substructure. Key Learnings: -> Modeled the problem using DP on string indices -> Handled base cases when one string is fully consumed -> Used memoization to avoid overlapping subproblems Strengthened understanding of string DP and cost-based optimization Language Used: Java -> Runtime: 34 ms (Beats 7.60%) -> Memory: 50.39 MB Consistent practice, deeper DP intuition, and steady progress 🚀 #LeetCode #DynamicProgramming #Java #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
--- For Loop in Java The for loop is used when the number of iterations is known in advance. It helps execute a block of code repeatedly in a controlled and readable way. Structure of a for loop: Initialization → Condition → Update Example: public class Main { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { System.out.println(i); } } } This loop prints numbers from 1 to 5 by initializing a counter, checking the condition, and updating the counter after each iteration. Why for loops are important: • Useful for iterating over arrays and strings • Commonly used in DSA problems • Helps write concise and readable code Understanding loops is essential for problem-solving and building logical thinking in programming. #Java #ForLoop #DSA #ProgrammingBasics #ControlFlow #SoftwareEngineering
To view or add a comment, sign in
-
Day 10 Problem Statement: The goal is to make two strings exactly the same by deleting characters, where deleting a character costs its ASCII value. We want to do this with the minimum total cost. Approach: Start comparing both strings from the beginning. At any position, you have two pointers: i pointing to s1 j pointing to s2 If the characters at these positions are the same, keep them and move both pointers forward (no cost). If the characters are different, you have two choices: Delete the character from s1 (pay its ASCII value and move i) Delete the character from s2 (pay its ASCII value and move j) Choose the option that costs less overall. If one string finishes, you must delete all remaining characters from the other string. Why Dynamic Programming is needed The same (i, j) positions appear again and again during recursion. To avoid recomputing, store the result for each (i, j) in a DP table. dp[i][j] represents: Minimum delete cost to make s1[i…] and s2[j…] equal. #HappyCoding #LeetCodeDaily #Java #DSA #ProblemSolving #Consistency
To view or add a comment, sign in
-
🔹 Day 98 – LeetCode Practice 📌 Problem: Path Sum II (LeetCode #113) 📊 Difficulty: Medium 🧠 Problem Overview: Given the root of a binary tree and a target sum, the task is to find all root-to-leaf paths where the sum of node values equals the target. Each valid path should be returned as a list of values. ✅ Approach Used: Traversed the tree using depth-first search. Maintained the current path and cumulative sum while moving down the tree. When a leaf node was reached, checked if the sum matched the target. Used backtracking to explore all possible paths correctly. 📈 Submission Results: Status: Accepted ✅ Runtime: 2 ms Memory Usage: 45.54 MB 💡 Reflection: This problem is a great example of how recursion and backtracking work together in tree problems. Managing state carefully is key to collecting all valid paths without duplication. #LeetCode #BinaryTree #DFS #Backtracking #Java #DSA #CodingPractice
To view or add a comment, sign in
-
-
Started the Arrays & ArrayLists module today. Arrays were the first place where I felt the shift from writing Java syntax to actually solving problems. I began with Linear Search — simple, but important. int[] arr = {4, 7, 1, 9, 3}; int target = 9; boolean found = false; for (int i = 0; i < arr.length; i++) { if (arr[i] == target) { found = true; break; } } System.out.println(found); // Output : true What this made clear: - arrays force you to think in terms of indices - traversal is the base of almost every array problem - breaking early (break) matters for efficiency - even simple problems depend on clean loop logic This felt like the right starting point before moving into more complex array operations. Continuing with Arrays & ArrayLists today. #Java #DSA #Arrays #LearningInPublic #Programming #CodingJourney #ProblemSolving #ComputerScience #DeveloperJourney #JavaDeveloper
To view or add a comment, sign in
-
Implemented a Binary Search Tree (BST) from scratch in Java and stepped through the insertion logic using the debugger. Visualizing how nodes are placed (left < root < right) really reinforces core DSA fundamentals beyond just writing code. Inserted values: 7, 8, 1, 3, 2, 5, 10, 4 Focusing on strengthening my problem-solving skills one data structure at a time. #DataStructures #Java #DSA #ComputerScience #LearningByDoing #Debugging
To view or add a comment, sign in
-
-
After finishing Arrays & ArrayLists, I revisited some core Java basics that I had already used everywhere — but hadn’t fully thought through. This revision focused on literals, operators, comments, and increment/decrement behavior. What became clearer this time: - literals are the actual constant values stored in memory, not just numbers in code - underscores in numeric literals exist for readability, not logic - operators don’t just “do operations” — they define how expressions are evaluated - the number of operands changes how an operator behaves - comments improve readability but are completely ignored by the compiler - pre-increment and post-increment can change program flow in subtle ways - a small change in expression order can change the final output Revisiting increment and decrement operators especially made me realize how easy it is to assume behavior instead of tracing execution step by step. This felt less like learning something new and more like removing hidden confusion from things I was already using daily. Sometimes going back to basics after solving harder problems makes everything cleaner. #Java #CoreConcepts #LearningInPublic #Programming #CodingJourney #JavaDeveloper #ProblemSolving
To view or add a comment, sign in
-
Day25 - LeetCode Journey Solved LeetCode 344: Reverse String in Java ✅ This was a simple problem on the surface, but it perfectly highlights how powerful clean logic can be. The goal was to reverse a string in-place using O(1) extra space, which means no extra arrays and no shortcuts. Just pure two-pointer logic. Using the left and right pointers and swapping characters step by step felt very satisfying. It’s one of those patterns that looks small but appears everywhere in interviews and real-world problems. Mastering this makes many string and array problems much easier later on. What I liked about this problem is how it teaches efficiency. Instead of creating new memory, we directly modify the existing array. That mindset of optimizing space is extremely important in DSA. Key takeaways: • Strong practice of the two-pointer technique • In-place operations with constant extra space • Clean and readable swapping logic • Reinforced fundamentals of string manipulation ✅ Accepted successfully ✅ 0 ms runtime with optimal performance Sometimes the simplest problems build the strongest foundations. Consistency with basics is what makes complex problems feel easier later 💪 #LeetCode #DSA #Java #Strings #ProblemSolving #Algorithms #CodingJourney #InterviewPreparation #TwoPointers #Consistency #DailyPractice
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