Day 10 / #100DaysOfCode LeetCode 712 — Minimum ASCII Delete Sum for Two Strings (Medium) Problem: Given two strings, delete characters from either string so that both become equal, while minimizing the sum of ASCII values of deleted characters. Approach: - Used Dynamic Programming where dp[i][j] represents the minimum delete sum to make substrings s1[i:] and s2[j:] equal - If characters match, move both pointers forward with no cost - Otherwise, delete one character and take the minimum cost between the two choices Key insight: This is a variation of LCS-style DP, but instead of maximizing length, we minimize the deletion cost. #LeetCode #DSA #Java
Minimize ASCII Delete Sum for Two Strings with Dynamic Programming
More Relevant Posts
-
📝 Day 12/30 – LeetCode #344 (Reverse String) | Java Although reversing a string seems simple, the constraint here is to do it in-place without using extra memory. Using built-in functions would defeat the purpose of the problem. By applying a two-pointer approach, I swapped characters from both ends of the array until they met in the middle. This resulted in a clean O(n) solution with O(1) space. This problem reinforced how even simple tasks can test understanding of constraints and memory efficiency. #LeetCode #Java #DSA #TwoPointers #Strings #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
📝 Day 9 Day 9/30 – LeetCode #125 (Valid Palindrome) | Java A direct string reversal works logically, but it doesn’t handle non-alphanumeric characters or case differences correctly. The main challenge here was filtering characters while still keeping the comparison efficient. Using a two-pointer approach, I skipped invalid characters and compared only lowercase alphanumeric values. This allowed a single-pass solution with O(n) time and O(1) space, while keeping the logic clear in Java. This problem reinforced how pointer-based techniques help simplify string validation problems. #LeetCode #Java #DSA #TwoPointers #Strings #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Ready to take a trip down memory lane—and build something cool in the process? This tutorial walks you through how to recreate the classic Snake game in Java, complete with logic, rendering, and controls. Sample code included. #Java #GameDev #CodingProjects #ProgrammingBasics #RheinwerkComputingBlog Read here: https://hubs.la/Q03-ngrv0
To view or add a comment, sign in
-
-
Understanding the difference between Value Types and Reference Types is a core concept in programming (especially in C#, Java, and .NET). 🔹 Value Types store actual data directly in stack memory. When you assign a value type to another variable, a copy of the data is created. Examples: int, bool, struct, etc. 🔹 Reference Types store a reference (address) to the actual object in heap memory. Multiple variables can point to the same object, so changes affect all references. Examples: class, string, array, object, etc. #ProgrammingBasics #DotNet #CSharp #Java #ValueTypes #ReferenceTypes #MemoryManagement #StackVsHeap #CodingConcepts #SoftwareDevelopment #DeveloperLife #LearnToCode
To view or add a comment, sign in
-
-
❌ == is NOT the same as equals() in java They look similar, but they answer two different questions. 🔸== operator Checks reference equality ➡️ Do both variables point to the same object? 🔸equals() method Checks logical equality ➡️ Do both the objects have same value/content? ☘️ Example String a = new String("Java"); String b = new String("Java"); System.out.println(a == b); // false (different objects) System.out.println(a.equals(b)); // true (same content) Even though the text is the same, a and b are stored at different memory locations. 💡Thumb Rule 🔸Use == for primitive types (int, double, boolean) 🔸Use equals for objects (String, custom classes) Getting this wrong can cause subtle bugs, especially when comparing Strings. #Java #SoftwareEngineering #Cleancode #Programming
To view or add a comment, sign in
-
-
Day 4/25 – LeetCode Challenge 🚀 🔸Problem: Max Consecutive Ones 🔸Difficulty: Easy 🔸Topic: Arrays, Sliding Window 🔸Language: Java Approach 🛠️: ▫️Traverse the binary array once while tracking the current streak of 1s. ▫️Increment the count when a 1 is found and reset it when a 0 appears. ▫️Maintain a variable to store the maximum streak seen so far. ▫️Handle edge cases like single-element arrays explicitly. ▫️This linear scan ensures optimal performance with minimal overhead. Key Learnings 📚: 🔹Efficient use of sliding window/counting techniques 🔹Importance of maintaining running state in array traversal 🔹Handling edge cases to avoid incorrect results 🔹Achieving O(n) time complexity with constant space #25DaysOfLeetCode #LeetCode #DSA #Java #ProblemSolving #Coding #Consistency
To view or add a comment, sign in
-
-
Day 6/30 – LeetCode #242 (Valid Anagram) | Java My initial thought was to sort both strings and compare them, but that adds unnecessary overhead. The more efficient approach was to use a frequency count, since only character occurrences matter here. By using an int[26] array and incrementing/decrementing counts while iterating through both strings, I was able to solve this in O(n) time with O(1) space. This problem reinforced how fixed-size arrays in Java can outperform maps when the character set is known. #LeetCode #Java #DSA #Strings #Hashing #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Which of the following is the correct signature of the Java main method? A) public void static main(String args[]), B) static public void main(String[] args), C) public static int main(String[] args), D) private static void main(String[] args) #java #python #programming #javascript #coding #programmer #html #developer #css #coder #php #computerscience #software #code #indonesia #webdevelopment #webdeveloper #softwaredeveloper #technology #codinglife #linux #webdesign #development #tech #programmingmemes #softwareengineer #pythonprogramming #programmers #javaprogramming #hackforge
To view or add a comment, sign in
-
-
LeetCode Practice - 896. Monotonic Array 🔷Logic Behind “Monotonic Array” (Java) ✔An array is called monotonic if it moves in only one direction: 📌Either it never decreases (increasing or equal) 📌Or it never increases (decreasing or equal) ✔So the idea is very simple: 📌Check if the array follows at least one of these directions. 🔍 Step 1 — Use two flags We take two boolean variables: boolean increasing = true; boolean decreasing = true; 🔄 Step 2 — Compare neighboring elements We loop through the array and compare every pair: What does this mean? If nums[i] > nums[i+1] → array is going down, so it cannot be increasing If nums[i] < nums[i+1] → array is going up, so it cannot be decreasing We keep eliminating possibilities. 🧪 Example 1 [1, 2, 2, 3] Comparisons: 1 ≤ 2 → ok for increasing 2 ≤ 2 → ok 2 ≤ 3 → ok No violation for increasing, so: increasing = true decreasing = false ➡ Result = true 🧪 Example 2 [1, 3, 2] Comparisons: 1 < 3 → not decreasing 3 > 2 → not increasing So: increasing = false decreasing = false ➡ Result = false ✅ Final decision ✔return increasing || decreasing; ✔If either increasing or decreasing is still true, the array is monotonic. #LeetCode #Java #CodingPractice #ProblemSolving #DSA #Array #DeveloperJourney #TechLearning
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
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