🚀 Daily DSA Practice – Day 62 | Dynamic Programming – Coin Change II (Java) Continuing my Dynamic Programming journey, today I solved a problem focused on counting combinations instead of minimizing values. 📌 Problem Solved (LeetCode): 518. Coin Change II (Medium) 🎯 Concept: Unbounded Knapsack (Count of Ways) 🧠 Problem Idea: Given an amount and coin denominations, find the number of combinations that make up that amount. Unlike Coin Change I, where we minimize coins, here we count total ways. DP Relation dp[j] = dp[j] + dp[j - coin] 🔍 What I Practiced: ✔ Difference between Minimization DP vs Counting DP ✔ Applying Unbounded Knapsack pattern ✔ Using 1D DP optimization ✔ Understanding order-independent combinations This problem helped me clearly understand how DP problems can change significantly based on whether we count ways or optimize values. #DSA #LeetCode #DynamicProgramming #Java #Knapsack #ProblemSolving #InterviewPreparation #Consistency
Dynamic Programming - Coin Change II (Java)
More Relevant Posts
-
Day 125 / 365 Days Coding Challenge — Solved Check if Strings Can Be Made Equal With Operations I. The key insight is that swaps are only allowed between indices with a gap of 2, which effectively forms two independent groups (0,2) and (1,3); instead of simulating swaps, we simply compare the sorted characters within these groups for both strings, and if both pairs match, the strings can be made equal. This problem reinforced that understanding constraints can eliminate brute force and lead to a constant-time solution. #Day125 #LeetCode #Java #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
Day 72 of #100DaysOfLeetCode 💻✅ Solved #3866 “First Unique Even Element” problem in Java. Approach: • Traversed the array to find even numbers • For each even number, counted its occurrences in the array • If the count is exactly 1, returned that number • Continued until the first unique even number is found • Returned -1 if no such number exists Performance: ✓ Runtime: 1 ms (Beats 99.36% submissions) 🚀 ✓ Memory: 45.15 MB (Beats 98.39% submissions) Key Learning: ✓ Practiced combining conditions (even + uniqueness) ✓ Improved understanding of nested loop logic ✓ Learned how to filter and validate elements efficiently Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 32/60 of #geekstreak60 🚀 Today’s POTD: Partitions with Given Difference Worked on a classic Dynamic Programming problem where the goal is to count the number of ways to partition an array into two subsets such that their sum difference equals a given value. The key insight is transforming the problem into a subset sum problem: Find the number of subsets with sum = (totalSum + diff) / 2. Used DP to efficiently count valid subsets — a standard pattern in subset/knapsack problems. #Day32 #geekstreak60 #GeeksforGeeks #DSA #Java #DynamicProgramming #SubsetSum #Knapsack #ProblemSolving #CodingChallenge #Consistency
To view or add a comment, sign in
-
-
🚀 𝐃𝐚𝐲 93/100 ✅ 𝐏𝐫𝐨𝐛𝐥𝐞𝐦: 𝐋𝐨𝐧𝐠𝐞𝐬𝐭 𝐂𝐨𝐧𝐭𝐢𝐧𝐮𝐨𝐮𝐬 𝐈𝐧𝐜𝐫𝐞𝐚𝐬𝐢𝐧𝐠 𝐒𝐮𝐛𝐬𝐞𝐪𝐮𝐞𝐧𝐜𝐞 Today’s problem focused on finding the length of the longest continuous increasing subarray. Unlike LIS, this must be strictly increasing AND contiguous. 💡 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬: Use a simple linear scan Maintain two variables: curr and maxLen Reset streak when order breaks Time Complexity: O(n), Space: O(1) 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Traverse the array and compare each element with the previous one: If increasing → extend streak Else → reset streak Keep updating maximum length #Day93 #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #ProblemSolving #KeepLearning
To view or add a comment, sign in
-
-
Last week, we faced a critical production issue that reminded me how tricky multithreading can be in Java. 🔍 Problem: Our application suddenly became slow under load. CPU usage was low, but requests were timing out. 🧠 Root Cause: After analyzing thread dumps using tools like jstack and VisualVM, we discovered a classic deadlock situation. Two threads were waiting on each other’s locks — and nothing was moving forward. ⚠️ Key Learnings: Always maintain a consistent lock ordering to avoid deadlocks Avoid excessive use of synchronized blocks Prefer high-level concurrency utilities like ExecutorService, ReentrantLock, and ConcurrentHashMap Monitor thread pools in production (size, queue, rejection policy) Use tools like jconsole, VisualVM, and thread dumps regularly 💡 Pro Tip: Multithreading issues rarely appear in development — they show up under real traffic. Always design with concurrency in mind. 👨💻 As developers, writing correct concurrent code is not just a skill — it's a responsibility. #Java #Multithreading #BackendDevelopment #ProductionIssues #SoftwareEngineering #Debugging #TechLearning
To view or add a comment, sign in
-
🚨 Race Condition vs Deadlock — The Most Common Confusion in Multithreading 🚨 For a long time, I thought race condition and deadlock were the same. They sound similar… both happen in multithreading… but the reality is very different. Here’s the clarity I wish I had earlier 👇 🔁 Race Condition When multiple threads access shared data at the same time, and the final result depends on execution order. 👉 Threads are running 👉 But result is unpredictable / incorrect Example: Two threads increment the same variable → expected = 2, actual = 1 ⛔ Deadlock When two or more threads are waiting for each other forever. 👉 Threads are blocked 👉 Program gets stuck (no output) Example: Thread 1 holds Lock A, waiting for Lock B Thread 2 holds Lock B, waiting for Lock A ⚡ Core Difference ✔ Race Condition → Wrong Result ✔ Deadlock → No Result 💡 Lesson Learned Understanding theory is one thing… But when you actually run multithreaded code, that’s when the real mystery unfolds under the hood. #Java #Multithreading #Concurrency #BackendDevelopment #SoftwareEngineering #CodingJourney
To view or add a comment, sign in
-
🚀 Day #82/100 – 𝐑𝐞𝐦𝐨𝐯𝐞 𝐄𝐥𝐞𝐦𝐞𝐧𝐭 (LeetCode) Today’s problem was Remove Element — a simple yet important question to understand in-place array manipulation. 🔍 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: We don’t need extra space! We can solve this using a two-pointer approach efficiently. 𝐖𝐡𝐲 𝐢𝐭 𝐰𝐨𝐫𝐤𝐬? We overwrite unwanted elements and keep only the valid ones at the beginning of the array. ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Initialize k = 0 Traverse array: If element ≠ val → place it at index k Increment k Return k (new length) ⏱️ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: O(n) 📦 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: O(1) #Day82 #100DaysOfCode #Java #DSA #LeetCode #TwoPointers #CodingJourney
To view or add a comment, sign in
-
-
Got hit with a NullPointerException today. I kept checking the logic again and again… Turns out, I forgot to initialize an object before using it. Fix: Proper initialization before calling methods Lesson learned: Always check for null before using objects. Debugging is frustrating but also the best teacher. #Java #Debugging #DeveloperLife
To view or add a comment, sign in
-
Day: 72/365 📌 LeetCode POTD: Count Submatrices With Equal Frequency of X and Y Medium Key takeaways/Learnings from this problem: 1. The key idea is converting the problem into numbers (like +1 and -1) so equal frequency turns into a sum = 0 problem. 2. 2D prefix sums really help here—you can quickly get submatrix sums without recalculating every time. 3. It’s a nice extension of 1D subarray problems to 2D, so knowing those basics pays off big time. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
🔥 𝗗𝗮𝘆 𝟴𝟬/𝟭𝟬𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 𝟭𝟱𝟳𝟮. 𝗠𝗮𝘁𝗿𝗶𝘅 𝗗𝗶𝗮𝗴𝗼𝗻𝗮𝗹 𝗦𝘂𝗺 | 𝗘𝗮𝘀𝘆 | 𝗝𝗮𝘃𝗮 Given an n×n matrix, return the sum of both diagonals without double-counting the centre on odd-sized grids. 𝗠𝘆 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵: ✅ Single loop — O(n) time, O(1) space ✅ Add both mat[i][i] and mat[n-i-1][i] per iteration ✅ Subtract mat[n/2][n/2] once if n is odd No extra arrays. No second pass. Just clean linear logic. The beauty of this one is that both diagonals can be walked in the same loop — and the edge case resolves with a single parity check. Sometimes the simplest solution is the best solution. 💡 📂 𝗙𝘂𝗹𝗹 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻 𝗼𝗻 𝗚𝗶𝘁𝗛𝘂𝗯: https://lnkd.in/gcWbQbbA 20 more days to go. Let's finish strong! 💪 #LeetCode #Day80of100 #100DaysOfCode #Java #DSA #CodingChallenge #ProblemSolving #Programming
To view or add a comment, sign in
Explore related topics
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