Skip to content
Y
yTube.SITE v8.0.4
media / worlds / tools / internet oddities
YouTube / video information

LeetCode 712 | Minimum ASCII Delete Sum for Two Strings | Java | Medium | 2D D P | CodeByTushu

Video information, playback and saved actions.

LeetCode 712 | Minimum ASCII Delete Sum for Two Strings | Java | Medium | 2D D P | CodeByTushu

Description: πŸš€ Welcome Back to CodeByTushu!

In today’s video, we solve LeetCode 712 β€” Minimum ASCII Delete Sum for Two Strings using String and Dynamic Programming in Java.

Given two strings s1 and s2, our objective is to find the lowest total ASCII value of deleted characters necessary to make both strings completely identical. This problem represents an ASCII-weighted variation of the classic Longest Common Subsequence (LCS) and Edit Distance paradigms. Rather than counting the number of deletions, we accumulate the numerical ASCII weight of every character removed, optimizing to preserve the subsequence with maximum aggregate ASCII value.

We formulate a 2D dynamic programming grid where dp[i][j] denotes the minimum ASCII deletion cost required to equalize prefix s1[0..i-1] with prefix s2[0..j-1]. When characters match at s1[i-1] and s2[j-1], no deletion is required, allowing us to carry forward the previous diagonal subproblem cost. When characters differ, we choose the minimum between deleting s1[i-1] or deleting s2[j-1]. This structured table computation achieves an optimal O(M * N) time and auxiliary space complexity.

πŸ”₯ Problem Highlights

βœ… 2D Dynamic Programming table formulation for character prefix alignment
βœ… Weighted variation of Longest Common Subsequence (LCS) based on ASCII values
βœ… Optimal subproblem recurrence with base cases handling empty string prefixes
βœ… Robust handling of strings of unequal length and completely disjoint characters
βœ… Idiomatic clean solutions across Java, Python, C++, and JavaScript
βœ… Optimal O(M * N) time complexity and O(M * N) auxiliary space complexity

⏱️ TIMESTAMPS

00:00 Intro
00:52 Problem Understanding
01:52 Observation & Mathematical Intuition
02:39 2D Dynamic Programming Approach
03:42 Java Code Walkthrough
04:49 Test Cases & Edge Cases Walkthrough
05:38 Time Complexity Analysis
06:11 Space Complexity Analysis
06:40 Summary & Outro

πŸ“‚ Problem Folder & Detailed Documentation:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/tree/main/solutions/January/10-January/712-Minimum-ASCII-Delete-Sum-for-Two-Strings

β˜• Java Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/January/10-January/712-Minimum-ASCII-Delete-Sum-for-Two-Strings/Solution.java

🐍 Python Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/January/10-January/712-Minimum-ASCII-Delete-Sum-for-Two-Strings/solution.py

⚑ C++ Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/January/10-January/712-Minimum-ASCII-Delete-Sum-for-Two-Strings/solution.cpp

🌐 JavaScript Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/January/10-January/712-Minimum-ASCII-Delete-Sum-for-Two-Strings/solution.js

πŸ”— LeetCode Source Code

πŸ“Œ Admin type the link

🌐 All LeetCode Solutions

πŸ“Œ https://codebytushu.com/Leetcode/

πŸ“± Join CodeByTushu on WhatsApp

Get coding updates, LeetCode solutions, daily questions and more.

https://whatsapp.com/channel/0029Vb8k5mCDeON2Xwlkxe40

❀️ Donate

πŸ“Œ https://codebytushu.com/Leetcode/donate.php

πŸ”₯ Perfect For

LeetCode Medium Problems
Java DSA Preparation
Dynamic Programming (DP)
String Algorithms
Edit Distance Patterns
Time Complexity Optimization
Coding Interview Preparation
Problem Solving

🌐 Follow CodeByTushu

▢️ YouTube: https://www.youtube.com/@codebytushu

πŸ“Έ Instagram: https://instagram.com/codebytushu/

πŸ’Ό LinkedIn: https://www.linkedin.com/company/codebytushu/

🌍 Website: https://codebytushu.com

πŸ™ GitHub: https://github.com/CodeByTushu

❀️ Don’t Forget To

πŸ‘ Like | πŸ’¬ Comment | πŸ”” Subscribe

πŸ’¬ Question of the Day

In the DP transition for LeetCode 712, if characters s1[i-1] and s2[j-1] match, what is the exact transition rule?

1️⃣ dp[i][j] = dp[i-1][j-1] + ASCII(s1[i-1])
2️⃣ dp[i][j] = dp[i-1][j-1]
3️⃣ dp[i][j] = min(dp[i-1][j], dp[i][j-1])
4️⃣ dp[i][j] = dp[i-1][j-1] + ASCII(s1[i-1]) + ASCII(s2[j-1])

#LeetCode712 #LeetCode #MinimumASCIIDeleteSumForTwoStrings #Java #JavaDSA #DynamicProgramming #StringAlgorithms #DSA #CodingInterview #ProblemSolving #LeetCodeMedium #DailyLeetCode #JavaProgramming #CodeByTushu

πŸ‘‡ Comment the answer below! πŸ”₯Β Close description
Β Β Β Β Β Β 
Videos related to "LeetCode 712 | Minimum ASCII Delete Sum for Two Strings | Java | Medium | 2D D P | CodeByTushu"