🚀 Day 168 of My LeetCode Journey 🚀 583. Delete Operation for Two Strings 🫧 In this problem, we are given two strings and need to find the minimum number of deletions required to make both strings the same. ▪️ Since we are only allowed to delete characters, the idea is to keep the characters that are common in both strings and remove the rest. ▪️ So first, I found the LCS between the two strings. The LCS represents the longest sequence of characters that appears in both strings in the same order. ▪️ I used dynamic programming to build a table where dp[i][j] stores the length of the LCS for the first i characters of word1 and the first j characters of word 2. ▪️ If the characters at the current positions match, we extend the subsequence by adding 1 to the previous result. ▪️ If they do not match, we take the maximum result from the previous possibilities. ▪️ After filling the table, we get the length of the LCS. ▪️ Finally, the minimum deletions needed are: (length of word1 − LCS) + (length of word2 − LCS) ▪️ This works because we keep the common characters and delete everything else from both strings. #LeetCode #DynamicProgramming #Strings #Python #CodingJourney #Day168 🔥
Min Deletions for Identical Strings
More Relevant Posts
-
🚀 Day 172 of My LeetCode Journey 🚀 44. Wildcard Matching 🫧 In this problem, I had to check if a given string matches a pattern that can contain special characters like ‘?’ and ‘*’. ▪️ The ‘?’ can match any single character, and ‘*’ can match any sequence of characters (even empty). ▪️ I used dynamic programming with recursion (memoization) to solve this. I compared the string and pattern from the end and tried to match them step by step. ▪️ If both characters match or if the pattern has a ‘?’, I move both pointers one step back. ▪️ If the pattern has '*,' I have two choices: 🔹 Treat as matching one character and move the string pointer 🔹 Or treat it as empty and move the pattern pointer ▪️ If the characters don’t match, then that path becomes invalid. ▪️ I also handled edge cases carefully. For example, if the string becomes empty, the pattern should still contain only ‘*’ to match. ▪️ To avoid recomputation, I stored results in a DP table. #LeetCode #DynamicProgramming #Strings #Python #CodingJourney #Day172 🔥
To view or add a comment, sign in
-
-
🚀 Day 169 of My LeetCode Journey 🚀 1092. Shortest Common Supersequence 🫧 In this problem, we are given two strings, and we need to build the shortest string that contains both of them as subsequences. ▪️ The key idea is related to the Longest Common Subsequence. If both strings share some common characters in order, we should include those characters only once in the final string. ▪️ First, I built a DP table to find the LCS length between the two strings. This helps us understand which characters are common between them. ▪️ After filling the DP table, I traversed it backwards to construct the final string. ▪️ If characters in both strings match, I add that character once to the result and move diagonally in the table. ▪️ If they don’t match, I move in the direction that gave the larger LCS value and add that character to the result. ▪️ If one string finishes before the other, I simply added the remaining characters from the other string. ▪️ In the end, I reversed the collected characters to get the shortest common supersequence, which contains both strings while keeping the length as small as possible. #LeetCode #DynamicProgramming #Strings #Python #CodingJourney #Day169 🔥
To view or add a comment, sign in
-
-
Just merged in initial text-based PDF/docx/xlsx/etc. support for Kodit and Helix Code Intelligence. The goal here is to replace our very convoluted RAG stack with the in-process Kodit Go library. Currently we have a complicated combination of haystack pipelines, typesense, multiple vectorchord instances and a lot of Python. Eventually this is going to get compressed into the control plane + a dedicated vectorchord instance, and that's it. Oh and this is me developing Helix, inside Helix, and asking the agent to demo it back to me. I love the whole "describe a UI workflow and let the agent figure it out" methodology for UI and smoke testing. It works really well.
To view or add a comment, sign in
-
-
🚀 New release: 𝗯𝗲𝘁𝘁𝗲𝗿-𝗿𝗲𝘀𝘂𝗹𝘁-𝗽𝘆 𝘃𝟭.𝟭.𝟬 Inspired by the better-result library in the JS ecosystem, I built better-result-py to bring a Rust-style Result type to Python. With v1.1.0, I introduced the 𝙾𝚔 and 𝙴𝚛𝚛 classes to make control flow clearer and more explicit: ✅ Success → 𝚛𝚎𝚝𝚞𝚛𝚗 𝙾𝚔(𝚃) ❌ Error → 𝚛𝚎𝚝𝚞𝚛𝚗 𝙴𝚛𝚛(𝚖𝚎𝚜𝚜𝚊𝚐𝚎) This helps with control flow if you're trying to achieve a more monadic-style error handling. 📦 Install: uv add better-result-py 👩💻 Repo: https://lnkd.in/dQ_4R46N
To view or add a comment, sign in
-
-
Just created my new tool and named it "ZIGBACK" for obvious reasons. It's a small red-team style experiment: dynamically generating a Zig-based reverse shell via Python and compiling it in real time. Chose Zig specifically for its low-level control, minimal runtime footprint, and ability to produce lean, dependency-free binaries ,which makes it very useful when you want to precisely understand how detection engines react to specific behaviors. Tested it against default Windows Defender to observe detection behavior. With careful API usage and structure, it remained Undetected , highlighting how much detection still depends on patterns rather than intent. Currently it is the first release, will be updating with a few more features. More to come!! 🤖 #redteaming #redteamtool #defenderbypass
To view or add a comment, sign in
-
Topic 7/100 🚀 🧠 Topic 7 — Lambda Functions Want to write a quick function in just one line? ⚡ 👉 What is it? Lambda functions are small anonymous functions defined using the lambda keyword. 👉 Use Case: Used in real-world applications for: Quick operations inside map(), filter() Sorting with custom logic Short, throwaway functions 👉 Why it’s Helpful: Reduces boilerplate code Makes code concise Useful for functional programming 💻 Example: # Normal function def square(x): return x * x # Lambda version square = lambda x: x * x print(square(5)) 🧠 What’s happening here? We replaced a full function definition with a single-line lambda expression. ⚡ Pro Tip: Use lambdas for small logic only — avoid them for complex functions. 💬 Follow this series for more Topics #Python #BackendDevelopment #100TopicOfCode #SoftwareEngineering #LearnInPublic
To view or add a comment, sign in
-
-
LeetCode Day 13 – Container With Most Water Today I solved the classic “Container With Most Water” problem — a great example of optimizing from brute force to an efficient solution! Problem Insight: We are given an array of heights, and we need to find two lines that together with the x-axis form a container that holds the maximum water. Approaches: Brute Force (O(n²)) Check all possible pairs Calculate area = width × min(height[i], height[j]) Keep track of maximum Optimal Approach – Two Pointer (O(n)) Start with two pointers at both ends Calculate area Move the pointer with smaller height inward Repeat until pointers meet Key Idea: The limiting factor is always the smaller height Moving the larger height won’t help increase area Complexity: Time: O(n) Space: O(1) What I learned: How two-pointer technique drastically reduces complexity Importance of understanding constraints before coding #LeetCode #Day13 #DSA #CodingJourney #Python #TwoPointers #ProblemSolving
To view or add a comment, sign in
-
-
Follow up to my last post, this is a complete walkthrough of my File Engine, including missing implementation details. 🔺User interacts with the program via interactive text input 🔺User can select to open a file or search a file 🔺All locations of a single file name are shown next to it if searched a directory (current or custom) 🔺O(1) file Lookup 🔺User can select a file to read 🔺All .PDF and .DOCX files are converted to .TXT and all the generated files are stored in the same directory as the original file 🔺The program does it all, quick and accurate. ---- #CPlusPlus #Python #BackendDevelopment #FullStackDeveloper #SoftwareEngineering #SystemDesign #TechProjects #DataStructures #GitHubProjects #BuildInPublic #Engineering #ComputerScience
To view or add a comment, sign in
-
Stop waiting for pip. Start using uv. ⚡ If you’re still using traditional tools to manage Python environments, you’re losing hours to loading bars. I’ve been diving into uv lately, and it’s a total game-changer for Python development. It’s a single tool (written in Rust) that replaces pip, venv, pip-tools, and pyenv. Why I’m switching: Insane Speed: It’s 10x–100x faster than pip. No hyperbole—it’s nearly instant. All-in-One: It manages your Python versions, virtual environments, and packages in one place. Reliability: It creates a uv.lock file by default, making deployments to VPS or containers 100% reproducible. Modern Features: It can run single-file scripts with inline dependencies automatically. Whether you're building FastAPI bots or complex data pipelines, your time is too valuable to spend watching packages install. Have you made the switch to uv yet, or are you sticking with the classic pip? #Python #SoftwareEngineering #Rust #DeveloperTools #OpenSource #Programming
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