🚀 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 🔥
LeetCode 1092: Shortest Common Supersequence
More Relevant Posts
-
Topic 10/100 🚀 🧠 Topic 10 — Partial Functions What if you could pre-fill some arguments of a function and reuse it later? 🤯 👉 What is it? Partial functions allow you to fix a few arguments of a function and generate a new function with fewer parameters. 👉 Use Case: Used in real-world applications for: Pre-configuring functions Simplifying repeated function calls Building reusable utilities 👉 Why it’s Helpful: Reduces repetition Makes code cleaner Improves readability 💻 Example: from functools import partial def multiply(x, y): return x * y double = partial(multiply, 2) print(double(5)) # Output: 10 🧠 What’s happening here? We fixed the value of x = 2, creating a new function (double) that only needs one argument. ⚡ Pro Tip: Use partial functions when you find yourself passing the same arguments repeatedly. 💬 Follow this series for more Topics #Python #BackendDevelopment #100TopicOfCode #SoftwareEngineering #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 39/100 – LeetCode Challenge Today’s problem: 406. Queue Reconstruction by Height This problem focuses on applying a Greedy approach with sorting to reconstruct a queue based on height and positional constraints. 🔍 Key Insight: Sort people by height in descending order and k value in ascending order, then insert each person at their respective index. 💡 What I learned: Importance of sorting strategy in greedy problems How insertion at a specific index can maintain constraints Thinking from the perspective of "who affects whom" (taller vs shorter) 🧠 Approach: Sort the array → (-height, k) Insert each person at index k 💻 Code (Python): class Solution: def reconstructQueue(self, people): people.sort(key=lambda x: (-x[0], x[1])) queue = [] for p in people: queue.insert(p[1], p) return queue ⏱️ Time Complexity: O(n²) Consistency is the key — showing up every day and improving step by step. #Day39 #LeetCode #100DaysOfCode #DSA #Python #CodingChallenge #GreedyAlgorithm #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 36 – LeetCode Journey Today’s problem: String to Integer (atoi) ✔️ Handled leading spaces and signs (+/-) ✔️ Processed numeric characters step by step ✔️ Managed overflow conditions within 32-bit integer range 💡 Key Insight: Carefully handling edge cases (like spaces, signs, and overflow) is just as important as the core logic. Small conditions can make a big difference in correctness. This problem strengthened my understanding of string parsing, edge cases, and boundary conditions. Learning to write robust and reliable code every day 💪🔥 #LeetCode #Day36 #Strings #EdgeCases #Python #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 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
-
-
🚀 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
-
-
📈 Day 53 of #GeekStreak60 🧩 Today’s problem was about checking whether a matrix is a Toeplitz Matrix. 🧠 Core Idea Every element should match its top-left diagonal neighbor ↖️ If all such pairs match → the matrix is Toeplitz ✅ 💡 What I Did ➡️ Traversed the matrix starting from (1,1) ➡️ Compared each element with its top-left neighbor mat[i-1][j-1] 🔍 ➡️ Returned ❌ false immediately if any mismatch was found 📚 What I Learned ✨ Simple observations about patterns (like diagonals) can lead to clean and efficient solutions ✨ You don’t always need complex logic — sometimes local checks are enough! 🔥 Day 53 complete Consistency + clarity = growth 🚀 #GeekStreak60 #GeeksforGeeks #NPCI #Day53 #ProblemSolving #Python #CodingJourney
To view or add a comment, sign in
-
-
Today I used Cortex Code to run evaluations on my Cortex Agent and the workflow is surprisingly smooth. Cortex Code can create eval datasets, configure metrics, kick off evaluation runs, and analyze results -- all from the CLI. No context-switching between Snowsight tabs. You describe what you want to test, it writes the SQL and Python, and you iterate from there. I was able to compare accuracy and groundedness across different prompt configs in about 15 minutes. The traces show exactly where the agent went off track, which makes debugging way faster than staring at raw logs. If you're building Cortex Agents, pair them with Cortex Code for evals. Works just as well for production monitoring as it does for continual testing as you tweak prompts and configs. What's your workflow for evaluating agents as they evolve? #Snowflake #CortexCode #CortexAI #AIAgents #AIObservability
To view or add a comment, sign in
-
-
🚀 Day 16 – DSA Daily Series Today’s Problem: Two Sum II – Input Array Is Sorted (LeetCode 167) Today’s problem was simple yet really interesting — especially because of how efficiently it can be solved using the two-pointer technique. 🧠 Problem Given a sorted array, find two numbers such that they add up to a target value and return their indices (1-based). Example: Input: [2,7,11,15], target = 9 Output: [1,2] 💡 Approach Instead of using extra space like a hashmap, I used: • Two pointers — one at the start and one at the end • If sum is too large → move right pointer left • If sum is too small → move left pointer right • Stop when target is found Clean and efficient ⚡ ⏱ Complexity Time Complexity: O(n) Space Complexity: O(1) 🔎 Key Learning When the array is already sorted, always think of two pointers before anything else — it saves both time and space. Solved it today and it felt really smooth to implement! 💯 Continuing to stay consistent and improve step by step 🚀 #DSA #LeetCode #Python #TwoPointers #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 32/60 — LeetCode Discipline Problem Solved: Find the Index of the First Occurrence in a String Difficulty: Easy Today’s problem was about locating a substring within a string — a classic example of pattern searching. Using a straightforward approach, I iterated through the string and checked each possible starting point where the substring could match. This reinforces how simple logic, when applied cleanly, can be highly effective. 💡 Focus Areas: • Strengthened understanding of string traversal • Practiced substring comparison • Improved handling of boundary conditions • Learned importance of index-based iteration • Focused on writing clean and readable code ⚡ Performance Highlight: Achieved 0 ms runtime (100% performance) Sometimes the answer isn’t hidden deep — it’s right there… waiting for a careful eye to notice it. #LeetCode #60DaysOfCode #100DaysOfCode #DSA #Strings #Algorithms #ProblemSolving #CodingJourney #SoftwareEngineering #Python #Developers #Consistency #TechGrowth
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
-
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