✏️ DSA Diary Day 16/100 📚🔤: Solving LeetCode’s “Minimum ASCII Delete Sum for Two Strings” 🚀✨ Today I worked on a Dynamic Programming + String Optimization problem on LeetCode 🔥👇 👉 Minimum ASCII Delete Sum for Two Strings This problem beautifully shows how DP helps minimize deletion cost while preserving the maximum common structure between two strings 🧠💡 🔹 My Approach 🛠️🧠 I used Bottom-Up Dynamic Programming (Tabulation) 🔽👇 🔸 Step 1: Define the DP Idea 📌 Instead of directly calculating what to delete, I focused on maximizing the ASCII value of the common subsequence between both strings. The more valuable the common part is, the less we need to delete 🔁✨ 🔸 Step 2: Decision Making 🔍 At every character comparison: 1️⃣ If both characters match → Add their ASCII value to the total 2️⃣ If they don’t match → Carry forward the maximum value from previous comparisons This is similar to the Longest Common Subsequence (LCS) concept, but with weights (ASCII values) instead of length 📈 🔸 Step 3: Getting the Final Answer 🧮 We calculate the total ASCII value of both strings, then subtract twice the value of the common subsequence. This ensures: ✔ Only unnecessary characters are deleted ✔ The deletion cost is minimum #LeetCode 🚀 #Java ☕ #DSA 🧠 #DynamicProgramming 📊 #ProblemSolving 💡 #CodingChallenge 💻 #100DaysOfCode 🔥 #DSADiaryByRethanya ✨ #Strings 🔤 #Tabulation 🧩 #LearnInPublic 📢 #TechJourney 🚀
LeetCode Minimum ASCII Delete Sum Solution
More Relevant Posts
-
📌 Today’s DSA Series Topic: Linked List A Linked List is a linear data structure where elements (called nodes) are stored in non-contiguous memory locations. Each node contains: Data – the value stored Next – reference to the next node The list starts with a head node and ends with NULL. Unlike arrays, linked lists are dynamic in size and allow efficient insertions and deletions. 🔹 CRUD Operations on Linked List (Explained visually in the images below 👇) ✅ Create – Insert a new node (at beginning or end) ✅ Read – Traverse the list from head to NULL ✅ Update – Modify the data of an existing node ✅ Delete – Remove a node and adjust pointers 📊 Time Complexity Overview Insert at Beginning: O(1) Read / Traverse: O(n) Update: O(n) Delete: O(1) / O(n) (based on position) 💬 Want to learn Linked List CRUD operations in a specific programming language (C, C++, Java, Python, JavaScript)? Comment the language name, and I’ll explain it with code examples. 🚀 Keep learning. Keep growing. #DSASeries #LinkedList #DataStructures #CRUD #Programming #TimeComplexity #SoftwareEngineering
To view or add a comment, sign in
-
-
Today I revisited design patterns this time while exploring Python after working extensively with Java and dove into the Facade Design Pattern. 💡 What is the Facade Pattern? It’s a structural pattern that provides a simple, unified interface to a complex system. Instead of interacting with multiple classes or subsystems, the client talks to a single “facade” class that handles everything behind the scenes. 🧩 Why it’s useful: ✔️ Reduces complexity for the caller ✔️ Improves readability & maintainability ✔️ Decouples client code from internal implementations ✔️ Makes large systems easier to use and evolve 📌 In simple terms: Think of it like a remote control—you press one button, and it coordinates several components (TV, speakers, set-top box) without you worrying about how each one works internally. Switching perspectives between Java and Python really highlights how these classic patterns stay relevant across languages—only the syntax changes, not the core ideas. Always fun sharpening fundamentals while learning something new 🚀 #Python #Java #DesignPatterns #FacadePattern #SoftwareEngineering #LearningJourney #CleanCode #BackendDevelopment
To view or add a comment, sign in
-
💻 Exploring Programming Across Languages! 🌐 I recently created a visual comparison of a basic program implemented in C++, Python, JavaScript, and Java. This illustration showcases how the same logic—printing "Hello, World!" and performing simple arithmetic operations—can look different depending on the programming language. 📌 Key Takeaways: 🔸 Syntax Differences: Even for simple tasks like variable declaration and addition, each language has its own syntax and style. 🔸 Ease of Use: Languages like Python are concise and readable, while C++ and Java require more boilerplate code. 🔸 Output & Console Handling: JavaScript uses console.log, C++ uses cout, Java uses System.out.println, and Python uses print. 🔸 Fundamentals Matter: Understanding these basics makes it easier to switch between languages and improves overall problem-solving skills. Whether you’re a beginner trying to grasp programming concepts or an experienced developer exploring multi-language proficiency, seeing the same logic implemented differently can provide great insights. 🔹 Languages Covered: C++, Python, JavaScript, Java 🔹 Concepts Highlighted: Variable declaration, arithmetic operations, printing output Curious to know your thoughts! How do you approach learning multiple programming languages? Which language’s syntax do you find the most intuitive? #Programming #Coding #CPlusPlus #Python #JavaScript #Java #SoftwareDevelopment #CodeComparison #LearningToCode #TechEducation
To view or add a comment, sign in
-
-
Why Rust is Changing the Way We Think About Memory If you are coming from Python or Java, Ownership feels like a puzzle. If you are coming from C, it feels like magic. I’ve been doing a deep dive into how Rust manages memory without a Garbage Collector (GC). Here is the "Cheat Sheet" for understanding the Rust memory model: 1. The Memory Split: Stack vs. Heap The Stack: Fast, LIFO (Last-In, First-Out). It stores fixed-size data like i32 or bool. The Heap: Flexible and dynamic. It stores data that grows, like String or Vec<T>. Rust doesn't just "leave" this memory; it tracks it via a pointer on the stack. 2. The 3 Golden Rules of Ownership Every value has a variable called its owner. There can only be one owner at a time. When the owner goes out of scope, the value is dropped (freed) instantly. 3. Move vs. Copy This is where the "aha!" moment happens. Copy: Simple types (integers) are duplicated. Move: For heap data, Rust moves the ownership. If you assign s2 = s1, s1 is no longer valid. This prevents "Double Free" errors—a common nightmare in C++. 4. Borrowing & The "One Writer" Rule You don't always want to give away ownership. That’s where References (&) come in. Immutable Borrowing: You can have as many readers as you want. Mutable Borrowing: You can only have ONE writer at a time. The Catch: You cannot have a writer and a reader at the same time. This is how Rust eliminates Data Races at compile time! 5. The Power of Box<T> and Vec<T> Using Box allows you to put a single value on the heap, while Vec gives you a growable array. Because of Rust's LIFO drop order, your memory is cleaned up the second it's no longer needed—no GC "stop-the-world" pauses required. The Result? Memory safety of a high-level language with the raw performance of a low-level language. - Hirusha Fernando - #RustLang #Programming #WebDevelopment #SoftwareEngineering #CodingTips #SystemsProgramming
To view or add a comment, sign in
-
-
🚀 Day 2 / 100 — NeetCode 150 Challenge 📌 Problem: Valid Anagram (LeetCode) 💻 Language: Java Continuing my 100 Days of Coding journey with NeetCode 150, focusing on string manipulation, hashing, and efficient comparisons. 🔹 Brute Force Approach I compared the two strings by sorting their characters and checking if the sorted results are equal. Convert both strings to character arrays. Sort each array. If both sorted arrays are identical, the strings are anagrams. Time Complexity: O(n log n) Space Complexity: O(n) 🔹 Optimized Approach — Method 1 (Frequency Array) I used a fixed-size character frequency array. Create an integer array of size 26 (for lowercase English letters). Increment the count for each character in the first string. Decrement the count for each character in the second string. If all values are zero at the end, the strings are valid anagrams. Time Complexity: O(n) Space Complexity: O(1) (since there are at most 26 characters) 🔹 Optimized Approach — Method 2 (HashMap) I used two HashMaps to track character frequencies. Iterate over both strings and populate their respective HashMaps. Use the equals() method to compare the two maps. If both maps are equal, the strings are anagrams. Time Complexity: O(n) Space Complexity: O(1) (bounded by at most 26 unique characters) ✅ Valid Anagram is a great example of how different data structures can solve the same problem efficiently, each with its own trade-offs. On to Day 3 — consistency is key! 💪 #100DaysOfCode #NeetCode150 #ValidAnagram #LeetCode #Java #DSA #ProblemSolving
To view or add a comment, sign in
-
-
✅ Day 57/75 – Dynamic Programming | Edit Distance 📌 Problem: Given two strings word1 and word2, find the minimum number of operations required to convert word1 into word2. 🔧 Allowed Operations: 🔺 Insert a character 🔺 Delete a character 🔺 Replace a character 💡 Approach: 🔺 Defined dp[i][j] as the minimum operations needed to convert the first i characters of word1 into the first j characters of word2 🔺 Used Dynamic Programming (Tabulation) to build the solution 🔺 Applied optimal substructure: 🔹 If characters match → carry forward dp[i-1][j-1] 🔹 If characters differ → 1 + min(insert, delete, replace) 📊 Complexity Analysis: 🔺 Time Complexity: O(n × m) 🔺 Space Complexity: O(n × m) #Day57 #75DaysOfCode #DynamicProgramming #EditDistance #LeetCode #Java #DSA #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
I built a programming language with algebraic effects KryhtaJS is a small language with JavaScript-like syntax that supports algebraic effects. Effects let you write code that "asks" for things without knowing how they'll be provided. The handler decides. let result = handle { let x = perform Ask!("value"); x * 2 } with { Ask!(label, resume) -> resume(21) }; // result = 42 This makes generators, async/await, exceptions, and state all expressible as patterns instead of language primitives. The interpreter is written in Rust, compiles to WebAssembly, and runs in your browser. Try it out, link in comments!
To view or add a comment, sign in
-
There’s no such thing as a *single best* programming language. What really matters is choosing the **right tool for the problem you’re solving**. -->Python isn’t superior to Java. -->Java doesn’t outperform JavaScript. -->JavaScript isn’t ahead of Go. Each language is designed with a **specific purpose** in mind. Every language brings its own strengths to the table: * **Python** – easy to learn and great for data-centric solutions * **Java** – reliable for scalable and enterprise-grade applications * **JavaScript** – essential for web and full-stack development * **Go** – built for speed and high-performance backend systems * **C / C++** – offers deep control at the system level True expertise isn’t about knowing dozens of languages. It’s about **developing the mindset of a programmer**. When your fundamentals—logic, problem-solving, and core concepts—are solid, picking up new languages becomes much simpler. Technology will keep changing, but **strong foundations never lose their value**. --- #Programming #DeveloperMindset #ProblemSolving #SoftwareDevelopment #TechLearning #STEMEducation #ArtificialIntelligence
To view or add a comment, sign in
-
-
🚀 .NET 10 & C# 14: The Game-Changer is officially here! 💻 If you haven’t looked at the latest LTS release yet, you’re missing out on a massive shift in how we write C#. We are moving from "Enterprise Only" to "C# Everywhere." Here are the top 5 features that are changing the game: 1️⃣ C# as a Scripting Language: Forget .csproj or .sln files for small tools. You can now run a single .cs file like Python. Use dotnet run script.cs and you're off! 🐍🚫 2️⃣ The field Keyword: Finally! Say goodbye to manual backing fields. Clean up your properties with set => field = value. 3️⃣ Extension Properties: Extension methods just grew up. You can now add properties and static members to existing types. 4️⃣ Insane Performance: Early 2026 benchmarks show up to 50% faster data materialization in EF Core 10. 5️⃣ AI & Modern Web: Built-in support for AI Agents, Passkeys, and native Server-Sent Events (SSE). If you’re on .NET 8 (LTS), it’s time to start planning your migration. The performance gains alone are worth the jump. 👇 Are you migrating to .NET 10 yet? What’s your favorite C# 14 feature? #dotnet #csharp #softwareengineering #programming #coding #dotnet10 #webdev
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
I am amazed to see your code, I have written 2 page db solution, and on top of that that doesn't work for all cases