*** Problem of the Day: Minimum Deletions to Make String Balanced One of the classic DP problems I recently solved. The goal Given a string containing only 'a' and 'b', remove the minimum number of characters so that all 'a's appear before all 'b's. 🔹 Approach I used (DP + Greedy logic): 1. Traverse the string recursively. 2. Keep track of 'b's seen so far (cntb). 3. For each character: 1. If 'a' appears after some 'b', delete it. 2. If 'b' appears before any 'b', either delete it or count it for future comparison. 4. Use memoization to avoid recomputation. Check out my solution here!👇 https://lnkd.in/gcVFdHei The solution essentially decides greedily whether to delete 'a' or 'b' at each step to minimize total deletions. A classic example where DP meets greedy thinking. #Coding #Programming #DataStructures #Algorithms #DynamicProgramming #DP #GreedyAlgorithms #ProblemSolving #LeetCode #CompetitiveProgramming #Tech #SoftwareEngineering #CodeDaily #LearningToCode #CodingChallenge #CodeOptimization #AlgorithmDesign #LinkedInLearning
Minimum Deletions to Balance String with DP and Greedy Logic
More Relevant Posts
-
🚀 Stop Writing Old-School Switch Statements! If you are still using the traditional switch with constant case and break keywords, you are missing out. C# Pattern Matching is a true game-changer for writing Clean Code. Why use Switch Expressions? 🔵 Conciseness: Reduces boilerplate significantly. 🔵 Readability: Expresses logic declaratively. 🔵 Safety: Better compiler checks for exhaustiveness. ⚡ Key Patterns to Master: 1️⃣ Relational: Use <, >, <= directly in logic. 2️⃣ Property: Match object properties { Status: "Active" }. 3️⃣ List Patterns (C# 11): Match arrays like [1, 2, ..]. Level up your C# and start using Pattern Matching today! #CSharp #DotNet #CleanCode #Programming #SoftwareEngineering #Backend
To view or add a comment, sign in
-
-
🚀 DSA Practice – Roman to Integer (LeetCode Problem) Today I solved an interesting problem related to string processing and mapping. 📌 Problem Statement: Roman numerals are represented by seven different symbols: I = 1 V = 5 X = 10 L = 50 C = 100 D = 500 M = 1000 For example: III = 3 VIII = 8 XX = 20 However, Roman numerals also follow a subtractive rule. If a smaller numeral appears before a larger numeral, we subtract the smaller value. Examples: IV = 4 (5 − 1) IX = 9 (10 − 1) XL = 40 (50 − 10) 🎯 Task: Given a Roman numeral string s, convert it into its integer equivalent. Example: Input: s = "MCMXCIV" Output: 1994 🧠 Approach Idea: Traverse the string and compare the value of the current symbol with the next symbol. If the current value is smaller than the next, subtract it. Otherwise, add it to the result. 💻 Language Used: C++ #DSA #LeetCode #CodingPractice #Programming #ProblemSolving #CPlusPlus
To view or add a comment, sign in
-
-
🚀 Day 58 of My DSA Challenge Today was all about diving deeper into Object-Oriented Programming in C++ and strengthening my core concepts that build the backbone of scalable software. 🔹 Concepts I explored: Shallow Copy vs Deep Copy: Also learn why we create the copy constructor as we have a compiler, but understand that copy constructors are being created for the deep copy, as compilers only create a shallow copy of the constructor. Constructors & Destructors Inheritance Modes (public, private, protected) Types of Inheritance: ▪ Single ▪ Multilevel ▪ Hierarchical ▪ Multiple ▪ Hybrid Understanding these concepts made me realize the power of OOP design in writing clean, reusable, and maintainable code. The deeper I go, the more I appreciate how these fundamentals shape real-world systems. #DSAChallenge #Day58 #CPP #OOPS #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
Most DP problems look different. But today I learned something powerful 👇 Subset Sum Partition Equal Subset Sum Partition With Minimum Difference Three problems. One core idea. If you understand Subset Sum, the other two are just smart variations of it. 💡 Dynamic Programming isn’t about memorizing patterns. It’s about recognizing them. Today’s takeaway: Define the state clearly → Everything becomes simpler. Small progress. Stronger foundations. #DSA #DynamicProgramming #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
I wanted to understand how programming languages actually work. So I built one. Nova is a statically-typed language I wrote from scratch in C++17. Not just a parser or a toy interpreter, a complete toolchain: The compiler has a lexer, parser, semantic analyzer, multi-pass optimizer, and code generator. It targets three backends: a stack-based bytecode VM, a JIT compiler that emits x86-64 machine code, and an LLVM IR generator. The language supports generics with monomorphization, traits with bounded generics, enums, pattern matching, first-class functions, closures, and a module system. Memory is managed by a mark-and-sweep garbage collector. But I didn't stop at the compiler. I built a step-through debugger, an LSP server for VS Code with diagnostics, hover, go-to-definition, and autocomplete, and published it as a VS Code extension on the marketplace. Then I compiled the whole thing to WebAssembly so anyone can try it in the browser. 196 tests. Zero external dependencies. Everything from scratch. Try it: https://lnkd.in/dMYy9jFA Code: https://lnkd.in/dCss3vb4 Extension: https://lnkd.in/dMnsXSPf #programming #compilers #cpp #webassembly #computerscience #softwareengineering
To view or add a comment, sign in
-
-
For years, I have been building software and systems using languages like Go, Rust, C/C++, Java, and JS. Working across so many different ecosystems teaches you a lot. You start to see exactly what makes a language a joy to use, and what creates unnecessary cognitive load. A few months ago, I decided to do something I had never done before: write my own systems programming language from scratch. It is called Vex. This is my first time designing a language and building a compiler. My goal was to combine the bare-metal control of C/C++, the memory safety of Rust, and the clean, atomic developer experience of Go. Instead of forcing developers to fight with a borrow checker or manage manual memory allocations, I wanted to see if the compiler could handle it autonomously. By analyzing the lifecycle of the code, Vex decides the optimal memory strategy under the hood, allowing you to focus purely on strict typing and clean architecture. It has been a massive learning curve. Vex is definitely not production-ready yet, but the core compiler, the LSP, and the testing pipeline are actually working. I wrote an article on Medium about this entire journey, the architectural decisions, and why I believe we need compilers that truly understand our code. If you are interested in language design, systems programming, or just building things from scratch, I would love to hear your thoughts. Website: https://vex-lang.org Read the full article:https://lnkd.in/dsCeWYDj
To view or add a comment, sign in
-
🚀 Solved My First Dynamic Programming Problem Today! Today I solved my first ever Dynamic Programming (DP) question — and I finally understand why everyone says DP is powerful 💡 🧩 The Problem : Given two strings, we need to count how many common consecutive substrings they share. 💡 Why This Was Challenging : At first, I thought: “Maybe I can generate all the substrings of both strings and compare…” But that quickly becomes messy and inefficient. 👉 Instead of generating everything, we can build the solution step-by-step using previous results. And that’s exactly what Dynamic Programming is about. 🧠 The Approach : Instead of storing the entire 2D table, I realized something important: 👉 To calculate the current row, I only need the previous row. So instead of using a full n × m table, I stored only one row at a time and updated it as I moved forward. Each cell represents: The length of the common substring ending at those two character positions. Then I followed a simple rule: • If characters match → extend the previous match by 1 • If characters don’t match → reset to 0 Every time we extend a match, we add that value to our total count. Because: Length 1 match → 1 substring Length 2 match → 2 substrings Length 3 match → 3 substrings So instead of explicitly listing substrings, we mathematically count them while building the solution. Time Complexity --> O(n × m) Space Complexity --> O(m) #DynamicProgramming #DataStructures #Algorithms #DSA #ProblemSolving #CodingJourney #CodingProblems #CompetitiveProgramming
To view or add a comment, sign in
-
-
🚀 DSA Deep Dive – Day 24 Solved my 5th 1-D Dynamic Programming problem today. 🚀 And I realized most developers misunderstand Palindrome problems. The question never said “use DP table.” 🤯 It simply asked to return the longest palindromic substring. Here’s what I learned 👇 • Palindromes expand from a center 🎯 • Every index can be a potential center • Handle both odd & even length cases • Expand while characters match • Track the longest window Brute force: O(n³) ❌ Better check: O(n²) Optimized (Expand Around Center): O(n²) with constant space ⚡ The interesting part? This problem is tagged under Dynamic Programming. But you don’t actually need a DP table to solve it efficiently. Lesson: DP isn’t about building tables. It’s about recognizing structure and eliminating unnecessary work. Smart thinking > Category memorization. Follow for more DSA insights 🚀 #LeetCode #DSA #DynamicProgramming #CodingJourney #SoftwareEngineering #InterviewPrep #ProblemSolving #100DaysOfCode #Developers #TechCareers
To view or add a comment, sign in
-
-
If a pointer holds a memory address, & a reference 𝗽𝗼𝗶𝗻𝘁𝘀 to data in memory, what makes them different? Since a variable is just a 𝗻𝗮𝗺𝗲 𝗯𝗶𝗻𝗱𝗶𝗻𝗴 to a memory address. A pointer is therefore a variable that stores another variable's memory address. A reference is the abstract 𝗰𝗼𝗻𝗰𝗲𝗽𝘁 of "referring to data somewhere else." Pointers are one type of 👉 𝗶𝗺𝗽𝗹𝗲𝗺𝗲𝗻𝘁𝗮𝘁𝗶𝗼𝗻 of that concept. When languages say "we have references" - 𝘁𝗵𝗲𝘆'𝗿𝗲 𝘂𝘀𝗶𝗻𝗴 𝗽𝗼𝗶𝗻𝘁𝗲𝗿𝘀 𝘂𝗻𝗱𝗲𝗿 𝘁𝗵𝗲 𝗵𝗼𝗼𝗱. They just won't let you access the raw memory addresses. Higher-level languages give you the behaviour without the control. C gives you both. #𝘀𝗼𝗳𝘁𝘄𝗮𝗿𝗲𝗲𝗻𝗴𝗶𝗻𝗲𝗲𝗿𝗶𝗻𝗴 #𝗽𝗿𝗼𝗴𝗿𝗮𝗺𝗺𝗶𝗻𝗴
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