🚀 Day 97/100 - Problem of the day :- Miniy ASCII Delete Sum for Two Strings. 🎯 Goal Find the minimum ASCII delete sum to make two strings equal. 💡 Core Idea Use Dynamic Programming to compute the maximum ASCII sum of the Longest Common Subsequence (LCS). Answer = (Total ASCII of both strings) − 2 × (LCS ASCII sum). 📌 Key Takeaway •Sometimes minimizing cost = maximizing what you keep. •Transforming problems smartly (Min → Max) simplifies the solution. 📄 Space Complexity : O(n × m) — DP table of two strings. ⏱️ Time Complexity : O(n × m) — Filling the DP matrix. #DSA #DynamicProgramming #LeetCode #Java #CodingJourney #ProblemSolving #Algorithms #TechSkills #100DaysChallenge
Min ASCII Delete Sum for Two Strings via Dynamic Programming
More Relevant Posts
-
Algorithm: Count and Say (No Code) Start with the base value "1" for the first term. For every next term: Read the previous term from left to right. Group consecutive identical digits together. For each group: Count how many times the digit appears. Say it as “count followed by the digit”. Combine all such groups to form the next term. Repeat the process until the required nth term is generated. Key Idea Each term is a verbal description of the previous term. Example "1" → one 1 → "11" "11" → two 1s → "21" "21" → one 2, one 1 → "1211" Complexity Insight Time: Proportional to the length of the generated sequence Space: Proportional to the length of the current term #LeetCode #CountAndSay #DSA #Algorithms #ProblemSolving #Java #Recursion #TwoPointers #CompetitiveProgramming #CodingPractice
To view or add a comment, sign in
-
-
Day 33/100 – LeetCode Challenge ✅ Problem: #1292 Maximum Side Length of a Square with Sum Less than or Equal to Threshold Difficulty: Medium Language: Java Approach: Prefix Sum + Binary Search on Square Size Time Complexity: O(m × n × log(min(m, n))) Space Complexity: O(m × n) Key Insight: Use 2D prefix sum to quickly compute sum of any square submatrix in O(1). For each cell, binary search the maximum square side length starting at that cell with sum ≤ threshold. Solution Brief: Built prefix sum matrix psum for O(1) submatrix sum queries. For each possible starting cell, used binary search to find largest valid square. Tracked global maximum side length across all positions. Optimizing submatrix queries with prefix sum. #LeetCode #Day33 #100DaysOfCode #BinarySearch #Java #Algorithm #CodingChallenge #ProblemSolving #MaxSquareSide #MediumProblem #PrefixSum #Matrix #Optimization #DSA
To view or add a comment, sign in
-
-
Day 47/100 – LeetCode Challenge ✅ Problem: #3013 Divide an Array Into Subarrays With Minimum Cost II Difficulty: Hard Language: Java Approach: Order Statistics with Balanced Trees Time Complexity: O(n log n) Space Complexity: O(n) Key Insight: Track greater count efficiently for two arrays during distribution. Need to compare current element with elements in both arrays - count how many are strictly greater. Used two TreeMaps to maintain sorted frequency counts with lazy rebalancing. Solution Brief: Maintained two balanced multisets (TreeMaps) for both arrays with size management. For each element, computed greater counts using total sizes and tail map views. Rebalanced collections when size constraints were violated to maintain optimal query performance. Advanced data structures for dynamic order statistics #LeetCode #Day47 #100DaysOfCode #HardProblem #DataStructures #TreeMap #Java #Algorithm #CodingChallenge #OrderStatistics #BalancedTrees
To view or add a comment, sign in
-
-
Maximum Height by Stacking Cuboids This question is a great example of LIS applied in 2D/3D. Key takeaways: Sorting cuboid dimensions before DP Using LIS to calculate maximum stack height Understanding how DP values change during iteration Why we add current height instead of using LIS[i] + LIS[j] Very helpful for improving DP transition clarity. #LeetCode #DynamicProgramming #LIS #DataStructures #Algorithm #Java #ProblemSolving #DSAPreparation #CodingJourney
To view or add a comment, sign in
-
-
#Day-126) LeetCode 712: Minimum ASCII Delete Sum for Two Strings ✅ In this problem, I implemented a Dynamic Programming approach to compute the minimum ASCII value of characters that must be deleted from two strings to make them equal. 🔍 What I learned: Designing DP states for string comparison Handling base cases efficiently Optimizing decisions using minimum cost strategies This challenge improved my problem-solving skills and reinforced core DSA concepts. 📌 Language: Java 📌 Topic: Dynamic Programming #LeetCode #DSA #DynamicProgramming #JavaDeveloper #ProblemSolving #CodingPractice #TechJourney
To view or add a comment, sign in
-
-
🔥 Day 305 – Daily DSA Challenge! 🔥 Problem: 📦 Subsets (Power Set) Given an integer array nums of unique elements, return all possible subsets (the power set). 💡 Key Insights: 🔹 Every element has two choices → include it or exclude it. 🔹 The total number of subsets for n elements is 2ⁿ. 🔹 Backtracking helps explore all possibilities in a clean, structured way. 🔹 Add the current subset to the result at every recursion level. 🔹 Move forward using i + 1 to avoid reusing elements. ⚡ Optimized Plan: ✅ Start with an empty subset ✅ Use backtracking to build subsets incrementally ✅ Add the current subset to results before branching further ✅ Try including each remaining element one by one ✅ Backtrack after exploring each choice ✅ Time Complexity: O(2ⁿ) ✅ Space Complexity: O(n) (recursion depth) 💬 Challenge for you: 1️⃣ How would this change if nums contained duplicate elements? 2️⃣ Can you solve this using bit masking instead of recursion? 3️⃣ How would you generate subsets of exactly k elements? #DSA #Day305 #LeetCode #Backtracking #Recursion #PowerSet #Java #ProblemSolving #KeepCoding #100DaysOfCode
To view or add a comment, sign in
-
-
Day 6 of Daily DSA 🚀 Solved LeetCode 27: Remove Element ✅ Approach: Used a two-pointer technique to modify the array in-place. Traversed the array once and shifted all valid elements to the front. No extra space used — clean and efficient. Complexity: • Time: O(n) • Space: O(1) LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.54 MB This problem reinforced a key DSA lesson: 👉 In-place solutions + pointers #DSA #LeetCode #Java #TwoPointers #ProblemSolving #Consistency #DailyCoding
To view or add a comment, sign in
-
-
Day 5 of Daily DSA 🚀 Solved LeetCode 268: Missing Number Approach: Used the mathematical sum formula to calculate the expected sum of numbers from 0 to n. Subtracted the actual sum of array elements to find the missing number in a single pass. Complexity: • Time: O(n) • Space: O(1) LeetCode Stats: • Runtime: 0 ms (Beats 100%) • Memory: 47.57 MB A simple yet powerful problem that shows how math can replace extra space and lead to clean, efficient solutions. #DSA #LeetCode #Java #ProblemSolving #Arrays #Consistency
To view or add a comment, sign in
-
-
Day 3 – DSA Journey | Arrays 🚀 Today’s focus was on 3-sum variations, where sorting + two pointers do most of the heavy lifting. ✅ Problems Solved 📌 3Sum 📌 3Sum Closest 🔹 3Sum Approach: Sorted the array Fixed one element and used two pointers to find valid triplets Skipped duplicates to avoid repeated results Key Learning: ✅ Sorting simplifies multi-pointer logic ✅ Duplicate handling is critical for correctness Complexity: ⏱ Time: O(n²) 📦 Space: O(1) (excluding output) 🔹 3Sum Closest Approach: Sorted the array Fixed one element and adjusted pointers based on how close the sum was to the target Updated the closest sum whenever a better match was found Key Learning: ✅ Greedy updates help converge quickly ✅ Absolute difference comparison is a powerful pattern Complexity: ⏱ Time: O(n²) 📦 Space: O(1) 🧠 Takeaway Once you understand sorting + two pointers, many array problems start looking familiar. Consistency > Complexity. On to Day 4 🔁🚀 #DSA #Arrays #TwoPointers #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
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