🚀 Day 20 of My DSA Journey Another day, another step closer to mastering Greedy Algorithms 🔥 📌 Problem Solved ✅ Lemonade Change 🧠 Key Learnings 🔹 1. Greedy Choice Matters At every step, we must return change in the most optimal way: Prefer $10 + $5 over 3 × $5 👉 This ensures future transactions remain possible 🔹 2. Simplicity > Complexity Initially thought of using HashMap ❌ But realized: ➡️ Only $5 and $10 matter ➡️ Simple variables are enough ✅ 🔹 3. Pattern Recognition This problem reinforced a key idea: Not every problem needs complex data structures 📊 Performance ⚡ Runtime: 2 ms (Beats 99.76%) 💾 Memory: 72.56 MB 💡 Big Takeaway “Greedy works when making the locally optimal choice leads to a globally optimal solution.” 🔥 Slowly building intuition for when to use: Greedy Heap HashMap Consistency is starting to pay off 🚀 #DSA #Java #GreedyAlgorithm #CodingJourney #LeetCode #100DaysOfCode #Programming
Mastering Greedy Algorithms with Java
More Relevant Posts
-
💡 Day 59 of LeetCode Problem Solved! 🔧 🌟 674. Longest Continuous Increasing Subsequence 🌟 🔗 Solution Code: https://lnkd.in/gzDVyZwa 🧠 Approach: • Linear Scan: Implemented a single-pass strategy to traverse the array and track the length of the current increasing streak. • Streak Tracking: Checked if each element is strictly greater than its predecessor. If true, extended the streak; otherwise, reset it to 1. Continuously updated the maximum length found. ⚡ Key Learning: • Reinforced the importance of recognizing that not every problem needs nested loops — a single traversal with smart state management is often sufficient. Resetting to 1 (not 0) when the streak breaks is a subtle but crucial detail that reflects real-world subarray thinking. ⏱️ Complexity: • Time: O(N) • Space: O(1) #LeetCode #Java #DSA #ProblemSolving #Consistency #CodingJourney #Algorithms #Arrays
To view or add a comment, sign in
-
-
🚀 Day 70 — LeetCode Practice ✅ Problem Solved: Minimum Operations to Make Array Sum Divisible by K 💡 What I learned today: • Understood how modulus (%) helps in solving optimization problems • Learned that instead of performing operations repeatedly, we can directly use math logic • Realized that the answer depends on sum % k • Improved thinking towards efficient (O(n)) solutions 📊 Approach: • Calculated total sum of the array • Found remainder using sum % k • That remainder itself gives the minimum operations required 🎯 Key Insight: Sometimes, problems look complex but can be solved using simple mathematical observations instead of brute force 🔥 Consistency is the key — showing up every day! #Day70 #LeetCode #DSA #CodingJourney #ProblemSolving #Consistency #Java
To view or add a comment, sign in
-
-
🚀 Day 8 of 30 Days Coding Challenge Today I solved a problem on LeetCode: Minimum Distance Between Three Equal Elements. 🔍 Approach: Initially implemented a brute-force solution using three nested loops (O(n³)). It worked for smaller constraints but highlighted the importance of optimizing. 💡 Key Learning: Instead of checking all possible triplets, grouping indices of identical elements and analyzing consecutive occurrences leads to a much more efficient solution. ⚡ Optimization Insight: Reduced time complexity from O(n³) → O(n) Leveraged HashMap to store indices and process only relevant combinations. 📈 Takeaway: This problem reinforced an important concept: 👉 When dealing with repeated elements, think in terms of grouping and patterns rather than brute force. Consistency is key — learning something new every day and improving step by step. #Day8 #30DaysOfCode #CodingChallenge #LeetCode #Java #DataStructures #Algorithms #ProblemSolving #CodingJourney #SoftwareDevelopment #LearnToCode #TechGrowth
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 1/50 🔍 Problem: Longest Substring Without Repeating Characters Today, I solved a classic sliding window problem that focuses on optimizing string traversal efficiently. 💡 Approach: Instead of checking all substrings (which would be inefficient), I used the Sliding Window + HashMap technique. - Maintained two pointers to track the current window - Used a HashMap to store the last index of characters - Whenever a duplicate appeared, directly shifted the left pointer to avoid unnecessary iterations ⚡ This helped in reducing time complexity significantly. 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(n) 📚 Key Learning: Efficient use of data structures like HashMap can drastically optimize problems by avoiding redundant computations. The sliding window technique is extremely powerful for substring-related problems. Consistency is key—looking forward to solving more such problems! 💪 #LeetCode #DataStructures #Algorithms #CodingJourney #ProblemSolving #Java #100DaysOfCode #Learning #StudentDeveloper
To view or add a comment, sign in
-
-
🚀 Day 572 of #750DaysOfCode 🚀 🔍 Problem Solved: Furthest Point From Origin Today’s problem was a great example of how a simple-looking question can be solved with the right observation 👀 💡 Key Insight: We don’t need to simulate every possible movement. Instead, we just count: 'L' → moves left 'R' → moves right '_' → flexible (can be either) 👉 To maximize distance from origin, use all '_' in the direction that increases the difference the most. 🧠 Approach: Count number of 'L', 'R', and '_' Net position = R - L Add all '_' to maximize distance 👉 Final Answer = |R - L| + '_' 📈 Complexity: Time: O(n) Space: O(1) ✨ Takeaway: Sometimes, instead of exploring all possibilities, you just need to convert the problem into counts and math. Simple logic → powerful result 💪 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #Algorithms #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 88 — LeetCode Practice 🚀 Today’s focus was on factorization and optimization techniques. ✅ Problem solved today: 🔹 Construct the Rectangle 💡 Key learnings from today: • Understood how to find factors of a number efficiently • Learned why starting from √area gives the closest dimensions • Strengthened concepts of minimizing difference between two values • Explored how mathematical logic can optimize brute-force solutions • Improved understanding of time complexity reduction 🧠 Approach used: Started checking from √area and moved downwards to find the first factor pair. This ensures length ≥ width and minimum difference. ⚡ Time Complexity: O(√n) 📦 Space Complexity: O(1) 📈 Progress: Getting better at optimizing solutions and thinking mathematically! #Day88 #LeetCode #DSA #Java #CodingPractice #ProblemSolving #Consistency #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 84 — LeetCode Practice 🚀 Today’s focus was on number manipulation and reversing digits. ✅ Problem solved today: 🔹 Mirror Distance of an Integer 💡 Key learnings from today: • Understood how to reverse an integer using modulus (%) and division (/) • Learned how to construct a number digit by digit • Practiced using Math.abs() for absolute difference • Strengthened understanding of basic arithmetic operations • Improved ability to implement clean logic in Java Initially, I solved the problem by manually reversing the number step by step. This helped me clearly understand how digits are extracted and rebuilt. Later, I realized that the core idea is simple: Find the reversed number and compute the absolute difference. This problem reinforced an important lesson: Strong fundamentals make even tricky-looking problems easy to solve. Digit by digit, improving every day 💪 On to the next challenge 🚀 #Day84 #DSA #LeetCode #ProblemSolving #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 6 🚀 Solved: Maximum Depth of Binary Tree (LeetCode 104) This is a classic recursion problem on trees. 💡 Key idea: The depth of a tree is 1 + the maximum depth of its left and right subtrees. 🔹 Approach: If the node is null → depth is 0 Recursively calculate depth of left and right Take the maximum and add 1 ⏱️ Time Complexity: O(n) 🔗 GitHub: https://lnkd.in/gz5mBpDx #DSA #LeetCode #Coding
To view or add a comment, sign in
-
🚀 LeetCode Challenge 10/50 🔍 Problem: Merge Sorted Array Today’s problem focused on efficiently merging two sorted arrays without using extra space. 💡 Approach: I used the Two Pointer technique (from the end): Started comparing elements from the back of both arrays Placed the larger element at the end of nums1 Continued this process until all elements were merged ⚡ This approach avoids unnecessary shifting and works in-place. 📊 Complexity Analysis: Time Complexity: O(m + n) Space Complexity: O(1) 📚 Key Learning: Thinking from the end can simplify problems and avoid extra operations. Two-pointer technique is extremely useful for array manipulation problems. Consistency is building confidence 💪 #LeetCode #Algorithms #DataStructures #ProblemSolving #CodingJourney #Java #100DaysOfCode #StudentDeveloper #Learning
To view or add a comment, sign in
-
-
🚀 Day 29 LeetCode Problem Solved: Longest Consecutive Sequence (128) Today I solved an interesting Data Structures & Algorithms problem on LeetCode. 💻 🔹 Problem: Given an unsorted array of integers, find the length of the longest consecutive elements sequence in O(n) time complexity. 🔹 Example: Input: [100, 4, 200, 1, 3, 2] Output: 4 👉 The longest consecutive sequence is [1,2,3,4]. 🔹 Approach: Instead of sorting the array (which takes O(n log n)), I used a HashSet to achieve O(n) time complexity. ✔ Store all numbers in a HashSet ✔ Identify the start of a sequence (num - 1 not present in the set) ✔ Expand the sequence forward (num + 1, num + 2...) ✔ Track the maximum length 🔹 Complexity: ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) 💡 Key Learning: Using HashSet efficiently can help optimize problems that involve searching and sequence detection. Excited to keep learning and improving problem-solving skills! 🚀 #leetcode #coding #java #datastructures #algorithms #softwaredeveloper #programming #codingjourney
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