🚀 Day 38 of mastering DSA patterns in Java Today I solved a very practical interval problem that combines merging logic + gap counting. 🧠 Pattern: Intervals → Merge + Count Gaps 🔹 Problem solved: LeetCode 3169 – Count Days Without Meetings https://lnkd.in/dnDiPA3M --- 💡 Problem Understanding We are given: • Total number of days • Meeting intervals in the form [start, end] (inclusive) • Meetings may overlap We need to count: ➡️ How many days have NO meetings scheduled? --- 🧠 Core Thinking This is NOT just counting gaps blindly. Because meetings can overlap, we must first handle overlapping ranges correctly. Step-by-step logic: 1️⃣ Sort meetings by start time 2️⃣ Track the latest meeting end seen so far. 3️⃣ For each meeting: If "current start > latestEnd + 1" → There is a gap → Add "(current start - latestEnd - 1)" to free days. Then update: "latestEnd = max(latestEnd, current end)" 4️⃣ After processing all meetings, add the days after the last meeting: "totalDays - latestEnd" --- 🛠 Why this works? Because we are effectively: • Merging overlapping intervals • Counting the gaps between merged intervals So it’s a classic: 👉 Intervals + Greedy + Gap Counting --- ⏱ Time Complexity Sorting → O(n log n) Linear scan → O(n) Total → O(n log n) --- 📌 How to recognize this pattern? If the question asks: • free days • available time • unused slots • count days without events → Think: Sort → Merge → Count gaps --- 🙏 Grateful to my mentor Pratyush Narain for helping me build strong intuition around interval merging logic. 📚 Big lesson of the day: Most “free time” problems are just merged intervals + gap calculation in disguise. Have you solved any gap-based interval problems recently? 👇 #DSA #KadanesAlgorithm #DynamicProgramming #ProblemSolving #DataStructures #Algorithms #CodingJourney #LeetCode #LearningInPublic #BTechCSE #SoftwareEngineering #PlacementsPrep #CodingPractice #TechCareer #Consistency
Count Days Without Meetings: LeetCode 3169
More Relevant Posts
-
🚀 Day 10 – LeetCode Practice Today, I solved the Combination Sum II problem on LeetCode: 🎯 Difficulty: Medium 💻 Language Used: Java 💡 Approach: • Given a list of candidate numbers (may contain duplicates) and a target, the goal was to find all unique combinations where the numbers sum to the target. • I applied a backtracking approach with careful duplicate handling: – Sorted the array to group duplicates. – During recursion, skipped elements that were the same as the previous at the same recursive level to avoid duplicate combinations. • This strategy ensured all valid combinations were found without repetition. ⏱ Complexity: • Time Complexity: depends on number of valid combinations • Space Complexity: O(n) for recursion stack 📚 Key Takeaway: This problem taught how sorting + backtracking + pruning helps explore the solution space efficiently and avoid duplicate results. Backtracking remains a powerful technique for combinatorial search. Consistent problem solving practice continues to strengthen my algorithmic intuition and confidence. 💪 #LeetCode #Java #DSA #Backtracking #Algorithms #ProblemSolving #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 DSA Consistency — Day 10 Continuing my consistency journey, today I solved the LeetCode problem “Sort Integers by The Number of 1 Bits.” 🔎 Key learning from today: The problem focused on sorting elements based on a custom criteria — primarily the count of set bits in each number, and secondarily their numeric value. I approached this by grouping numbers according to their set bit count using ordered data structures and then sorting within each group. 💡 This problem reinforced: ✅ Bit manipulation fundamentals ✅ Custom sorting logic ✅ Effective use of Java Collections (TreeMap + ArrayList) ✅ Translating problem constraints into clean implementation Maintaining daily problem-solving discipline is helping me sharpen both my problem-solving mindset and implementation clarity. 📌 You can check out my solution here: https://lnkd.in/d-ESnvjq #DSA #LeetCode #Consistency #ProblemSolving #Java #BitManipulation #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 5 – LeetCode Practice Today, I solved the Generate Parentheses problem on LeetCode: 🎯 Difficulty: Medium 💻 Language Used: Java 💡 Approach: • Given an integer n, the task was to generate all combinations of well-formed parentheses of length 2n. • I applied a backtracking technique to build combinations by adding ( and ) step by step. • Ensured the number of closing parentheses never exceeded opening ones during recursion. • Backtracking pruned invalid paths and constructed only valid sequences. ⏱ Complexity: • Time Complexity: O(Cn) (Catalan number of combinations) • Space Complexity: O(n) (for recursion stack) 📚 Key Takeaway: This problem strengthened my understanding of recursive backtracking and how constraints can guide efficient exploration of combinatorial solutions. Consistent problem-solving practice improves both logic and implementation confidence. 💪 #LeetCode #Java #DSA #Backtracking #Algorithms #ProblemSolving #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 4 – LeetCode Practice Today, I solved the 4Sum problem on LeetCode: 🎯 Difficulty: Medium 💻 Language Used: Java 💡 Approach: • Given an integer array nums and a target value, the goal was to find all unique quadruplets that sum up to the target. • I started by sorting the array to simplify searching and handling duplicates. • Used a nested loop structure with a two-pointer technique for the inner pair search: – The first two pointers fixes the first two elements, and the two pointers inside find matching pairs. • Skipped duplicates carefully to ensure unique quadruplets in the final list. ⏱ Complexity: • Time Complexity: O(n³) • Space Complexity: O(1) (excluding result storage) 📚 Key Takeaway: This problem strengthened my understanding of multi-pointer techniques, careful duplicate handling, and how sorting can significantly simplify complex combination searches. Consistent problem-solving practice continues to build my algorithmic intuition and coding confidence. 💪 #LeetCode #Java #DSA #TwoPointers #Sorting #ProblemSolving #Algorithms #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
Daily DSA Update – Day 26 Solved: Add Binary (LeetCode) Today’s problem was about adding two binary strings and returning their sum as a binary string. Problem: Given two binary strings a and b, return their sum as a binary string. Approach: I simulated the same process we use while doing binary addition manually. Starting from the end of both strings, I added corresponding digits along with a carry value. After calculating the sum, I appended the result bit and updated the carry. Finally, I reversed the result to get the correct binary order. Key Learning: Problems like this highlight the importance of understanding how operations work internally rather than relying on built-in conversions. What this strengthened: • String traversal from right to left • Handling carry in binary operations • Using StringBuilder for efficient string manipulation • Implementing mathematical logic in code Each daily problem adds a small but meaningful improvement in problem-solving ability. On to the next challenge. #DSA #DataStructures #Algorithms #Java #LeetCode #ProblemSolving #CodingJourney #TechLearning
To view or add a comment, sign in
-
🚀 Day 90 of My 100 Days LeetCode Challenge | Java Today’s challenge was a fascinating logic + mathematical insight problem. The task was to generate a binary string that does not exist in a given list of binary strings, where all strings have the same length. Instead of trying every possible combination, the solution becomes much simpler when you use the idea of diagonal flipping. By flipping the i-th bit of the i-th string, we guarantee that the newly created string differs from every string in the list at least in one position. This clever trick ensures the generated string is always unique. ✅ Problem Solved: Find Unique Binary String ✔️ All test cases passed (186/186) ⏱️ Runtime: 0 ms 🧠 Approach: Mathematical Insight (Diagonal Construction) 🧩 Key Learnings: ● Sometimes the smartest solutions come from mathematical reasoning rather than brute force. ● The diagonalization technique guarantees uniqueness. ● Understanding problem constraints can drastically simplify the approach. ● Logical insights can reduce exponential possibilities to linear solutions. ● Elegant algorithms often come from simple observations. This problem was a great reminder that a small logical trick can outperform complex algorithms. 🔥 Day 90 complete — sharpening my problem-solving intuition and algorithmic thinking. #LeetCode #100DaysOfCode #Java #Math #Algorithms #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Every problem teaches something new — today it was LeetCode 50: Pow(x, n) At first, it looked simple: just calculate power. But the real challenge was optimizing it and handling edge cases like negative powers and Integer.MIN_VALUE overflow. Learned how Binary Exponentiation can turn an O(n) solution into O(log n) — that’s the beauty of algorithms! Moments like these remind me that problem-solving is not just about writing code, but thinking deeper. #LeetCodeJourney #DSA #KeepLearning #Java #ProblemSolving
To view or add a comment, sign in
-
-
Day 19/100 of DSA , (Arrays) 🚀Toady I Solved: classic 4Sum problem I worked on solving the 4Sum problem using Java, where the goal is to find all unique quadruplets in an array whose sum equals a given target value. 🔹 Approach Used: • First, sort the array to make traversal easier and handle duplicates. • Fix the first two elements using nested loops. • Use the two-pointer technique to find the remaining two elements whose sum matches the target. • Carefully skip duplicate values to ensure only unique quadruplets are included in the result. ⚡ Time Complexity: O(n³) ⚡ Space Complexity: O(1) (excluding the output list) Problems like this are a great way to strengthen understanding of two-pointer patterns and array manipulation. Consistently practicing these patterns helps improve logical thinking, debugging skills, and writing optimized code. Every problem solved is another step toward becoming a better developer. 🚀 #Java #DSA #Algorithms #ProblemSolving #CodingJourney #LearningInPublic #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Day 8 – LeetCode Practice Today, I solved the Count and Say problem on LeetCode: 🎯 Difficulty: Easy / Medium 💻 Language Used: Java 💡 Approach: • The “count and say” sequence is built by reading off digits of the previous term — counting repeated digits then describing them. • I started from the base term "1" and iteratively built the next term by scanning the current string and describing consecutive runs of the same character. • This continues until the nth term is generated. ⏱ Complexity: • Time Complexity: O(n × k) (n = sequence length, k = average term length) • Space Complexity: O(k) 📚 Key Takeaway: This problem improved my understanding of string manipulation and iterative pattern construction. Carefully building and transforming sequences is a useful technique in many real-world problems. Consistent problem-solving practice continues to strengthen my logic and coding confidence 💪 #LeetCode #Java #DSA #Strings #ProblemSolving #Algorithms #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 8 – LeetCode Practice Today, I solved the Search Insert Position problem on LeetCode: 🎯 Difficulty: Easy 💻 Language Used: Java 💡 Approach: • Given a sorted array and a target value, the task was to return the index where the target should be inserted if it is not found. • I used an efficient binary search approach to locate the correct position in O(log n) time. • If the target exists, return its index; otherwise, return the index where it would be inserted to maintain sorted order. ⏱ Complexity: • Time Complexity: O(log n) • Space Complexity: O(1) 📚 Key Takeaway: This problem reinforced how binary search can be slightly adapted to both find and insert positions in a sorted array without scanning the entire list — an essential optimization in sorted data structures. Consistent problem-solving practice continues to build intuition for time-efficient algorithms and clean implementations. 💪 #LeetCode #Java #DSA #BinarySearch #Algorithms #ProblemSolving #CodingPractice #100DaysOfCode #SoftwareDeveloper
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