🚀 Day 163 of My LeetCode Journey 🚀 416. Partition Equal Subset Sum 🫧 We are given an array of integers and need to determine whether it can be split into two subsets with equal sum. ▪️ First, we calculate the total sum of the array. If the sum is odd, it cannot be divided into two equal parts, so return False. ▪️ If the sum is even, the problem becomes finding a subset whose sum equals total/2. ▪️ Treat this as a subset sum problem, where we check if we can form the target sum using the given numbers. ▪️ Our DP state is defined as (i, target), which represents whether we can form the target sum using elements from index. ▪️ At each index, we have two choices: either pick the element or not pick it. ▪️ If we pick the element, we reduce the target by nums[i]; if we skip it, the target remains the same. ▪️used memoization (dp[i][target]) to store results and avoid recomputing the same. ▪️ If successfully found a subset with a sum of total/ 2, it means the remaining elements automatically form the other subset with the same sum. #LeetCode #DynamicProgramming #Python #CodingJourney #Day163 🔥
LeetCode 416: Partition Equal Subset Sum
More Relevant Posts
-
🚀 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
-
-
🚀 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 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
-
-
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
-
-
🚀 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
-
-
🚀 #100DaysOfLeetCode – Day 47 📌 Problem: Find the Peaks (LeetCode 2951) A peak element in the array is an element that is strictly greater than its immediate neighbors. ⚡ Important Points First and last elements cannot be peaks. We check each element from index 1 to n-2. If the current element is greater than both neighbors, it is a peak. 🧠 Approach: 1️⃣ Traverse the array from 1 to n-2 2️⃣ Compare each element with its left and right neighbor 3️⃣ If both conditions satisfy, store its index 4️⃣ Return the list of peak indices ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) (excluding output list) ✅ Successfully solved and accepted on LeetCode. #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode #Python #Algorithms
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
-
-
Day 68 of 365 Days of code Qn 1) Min stack Approach: use an extra stack(to store minimum element up to the particular index) for push: push the value into the stack, check if the val is lesser than the element at the top of minstack, if yes, push the value, else push the copy of the top element in minstack for pop: pop from both of the stacks for returnmin: return minstack[top] :) good night #365daysOfCode #NeetCode #leetcode #DSA #python #LeetCode #ProblemSolving #Algorithms #365dayschallenge
To view or add a comment, sign in
-
-
🚀 Day 11 of Consistency | #75DaysLeetCodeChallenge 🧠 Today’s Problem : Two Sum II – Input Array Is Sorted (#167) 💡 Key Learning: This problem highlights the power of the two-pointer technique on a sorted array, helping reduce time complexity efficiently compared to brute force. ⚡ Approach: Use two pointers → left (l) at start & right (r) at end → If sum == target → return indices If sum < target → move l++ If sum > target → move r-- 🧠 Why this works: Takes advantage of sorted array Reduces complexity → O(n) No extra space required → O(1) 🔥 Result : ✔️ Runtime: 0 ms (Beats 100%) 📈 Mastering patterns like two pointers is key to cracking medium & hard problems. Consistency is compounding. Keep going. 💪 #Day11 #LeetCode #DSA #CodingJourney #100DaysOfCode #Python #TwoPointers #Consistency
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
-
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