📅 Day 46 of #100DaysOfLeetCode 🧩 Problem: 2054. Two Best Non-Overlapping Events ⚙️ Difficulty: Medium 🚀 What I learned today: How to maximize value by selecting at most two non-overlapping intervals Importance of sorting events by end time to enable efficient lookups Used prefix maximum array to store the best value so far Applied binary search to find the last event that ends before the current one starts Achieved an optimal O(n log n) solution for large constraints 🧠 Key Insight: Instead of checking all pairs, precompute the best past event and combine it smartly using binary search. 💡 Techniques Used: Sorting • Binary Search • Prefix Max • Greedy ⏱ Complexity: Time: O(n log n) Space: O(n) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
Maximizing Non-Overlapping Events with Binary Search
More Relevant Posts
-
#Day_59 Problem: 4Sum (LeetCode 18) Day 57 pushed the limits with 4Sum — finding all unique quadruplets equal to a target! 💥 🧠 Key Takeaways: This is an extension of 3Sum → fix two elements + two pointers. Sorting is the backbone. Duplicate skipping at both outer and inner levels is critical. Use long for sum to avoid overflow. ⚙️ Optimized Approach: Sort the array. Fix i and j. Apply two pointers for remaining part. Carefully skip duplicates. ⏱️ Complexity: O(n³), but still efficient compared to brute force. 📌 This problem taught me: How patterns scale from 2Sum → 3Sum → 4Sum. Writing clean, duplicate-free logic. Consistency + patterns = confidence! 💪 #Day57 #4Sum #LeetCode #Java #DSA #CodingPractice #LearnByDoing
To view or add a comment, sign in
-
-
Solved LeetCode 4 – Median of Two Sorted Arrays ✅ Yeah, I know. This is a Hard problem and the expected solution is O(log(min(n, m))) using binary search and partitioning. But today, I went with clarity first. I combined both arrays, sorted them, and directly computed the median. 📌 Result? ✔️ All test cases passed ✔️ Correct output ✔️ Clear logic Is it the optimal solution? ❌ Is it a valid one? ✅ And that’s the point. Sometimes the real learning is: Understanding why a brute-force solution works Then understanding why it’s not optimal And only then moving to the complex solution Hard problems aren’t solved in one jump. They’re solved in iterations. Binary search partitioning is next. But today, correctness comes first. #LeetCode #DSA #ProblemSolving #Java #CodingJourney #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 147 | Frequency Counting Across Multiple Strings Today’s problem was a clean exercise in comparing character frequencies across multiple inputs. 🧩 Problem Solved: 1002. Find Common Characters 🔍 Approach: • Initialized a frequency array using the first word. • For each subsequent word, counted character frequencies and kept the minimum count for each character. • Constructed the result by adding each character as many times as its final minimum frequency. ✨ Key Insight: Using minimum frequency across all strings ensures only truly common characters are included. 📚 Topics: Hashing · Strings · Frequency Counting 💻 Platform: LeetCode #LeetCode #DSA #ProblemSolving #DailyCoding #Strings #Hashing #Java #Consistency
To view or add a comment, sign in
-
-
🚀 DSA Series – Day 29 📌 Problem: Find the Duplicate Number (LeetCode) Today I worked on a classic array problem where the goal is to find the single duplicate number in an array containing n+1 integers from 1 to n. 🧠 What I learned Instead of sorting or nested loops, we can use a frequency array to track how many times each number appears. If a number appears more than once, that is our duplicate. 💡 My Approach -Create an extra array to store counts -Traverse the input array and increase the count -Scan the count array to find the value with frequency > 1 ⏱ Complexity Time: O(n) Space: O(n) #DSA #LeetCode #Java #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 44 of #100DaysOfCode Solved LeetCode Problem #961 – N-Repeated Element in Size 2N Array This problem was about identifying the element that repeats N times in an array of size 2N. The key insight is that the repeated element must appear very close to itself, allowing an efficient linear scan without extra space. Key Learnings: -> Used observation-based logic instead of extra data structures -> Checked only nearby indices to detect repetition early -> Achieved optimal O(n) time and O(1) space -> Reinforced pattern recognition in array problems Language Used: Java -> Runtime: 0 ms (Beats 100.00%) -> Memory: 47.85 MB Small observations can lead to optimal solutions 🚀 #LeetCode #Java #Arrays #ProblemSolving #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
🔹 Day 95 – LeetCode Practice 📌 Problem: Maximum Depth of Binary Tree (LeetCode #104) 📊 Difficulty: Easy 🧠 Problem Overview: Given the root of a binary tree, the task is to determine its maximum depth. The maximum depth is defined as the number of nodes along the longest path from the root node down to the farthest leaf node. ✅ Approach Used: Traversed the binary tree using depth-first search. At each node, tracked the current depth. Updated the maximum depth whenever a deeper level was reached. Recursively explored both left and right subtrees. 📈 Complexity Analysis: Time Complexity: O(n), where n is the number of nodes Space Complexity: O(h), where h is the height of the tree 🚀 Submission Results: Status: Accepted ✅ Runtime: 0 ms (Beats 100%) Memory: 44.51 MB (Beats 27.65%) 💡 Reflection: This problem reinforces the fundamentals of tree traversal and recursion. A simple yet important exercise to strengthen understanding of binary tree depth calculations. #LeetCode #DSA #BinaryTree #DFS #ProblemSolving #Java #CodingPractice #Learning
To view or add a comment, sign in
-
-
🔹 Day 96 – LeetCode Practice 📌 Problem: First Missing Positive (LeetCode #41) 📊 Difficulty: Hard 🧠 Problem Overview: Given an unsorted integer array, the task is to find the smallest positive integer that is missing from the array. The challenge lies in solving it efficiently with strict constraints on time and space. ✅ Approach Used: Stored all values from the array for quick lookup. Iterated from the smallest possible positive integer to identify the first missing value. Returned the earliest number that was not present. 📈 Submission Results: Status: Accepted ✅ Runtime: 14 ms Memory Usage: 93.44 MB 💡 Reflection: This problem highlights the importance of understanding constraints clearly. While multiple approaches exist, optimizing time and space is the key learning takeaway from this question. #LeetCode #DSA #ProblemSolving #Arrays #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
#200DaysOfCode – Day 109 Problem: LeetCode 17 – Letter Combinations of a Phone Number Task:- Given a string of digits (2–9), return all possible letter combinations based on the phone keypad mapping. Example: Input: digits = "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] My Approach: Used a mapping array to store digit-to-letter relationships. Applied backtracking to build combinations character by character. Once the current combination length matched the input length, added it to the result list. Used StringBuilder for efficient string manipulation. Time Complexity: O(4ⁿ) Space Complexity: O(n) (recursive stack) Backtracking is a powerful technique when dealing with combinations and permutations. Breaking the problem into smaller recursive steps makes complex logic much easier to handle. #takeUforward #200DaysOfCode #LeetCode #Java #Backtracking #Recursion #ProblemSolving #DSA #CodeNewbie #Consistency #LearnEveryDay
To view or add a comment, sign in
-
-
Today Morning,With the fresh morning, I solved the Reverse Integer problem on LeetCode. Instead of directly reversing the number, I focused first on handling edge cases — especially integer overflow. 🔍 Key Insight: Before pushing a digit into the reversed number, I checked whether the value would exceed the 32-bit integer range (Integer.MAX_VALUE / Integer.MIN_VALUE). This ensures correctness even for tricky inputs like 1534236469. 💡 What I learned: Always validate constraints before implementation Edge cases can make or break a solution Writing safe, overflow-aware code is crucial for real-world systems Consistently practicing DSA problems to sharpen logic and build strong fundamentals. On to the next challenge! 💪 Github link https://lnkd.in/gGUy_MKZ #LeetCode #DSA #Java #ProblemSolving #CodingPractice #LearningEveryDay
To view or add a comment, sign in
-
-
Day 136 of My LeetCode 150 Days Journey 🚀 💡 Problem: 540. Single Element in a Sorted Array You’re given a sorted array where every element appears exactly twice, except for one element that appears only once. The task is to find that single element in O(log n) time and O(1) space. --- ✅ Approach (Java): Binary Search Use binary search on the sorted array. Key observation: Pairs start at even index before the single element. After the single element, the pairing pattern shifts. At each step: Check whether mid forms a valid pair with its neighbor. If the pattern is correct → move right Else → move left Eventually, left points to the unique element. --- ⚙ Core Idea: Use index parity (even/odd) with binary search to detect where the pairing breaks. --- 📈 Key Learnings: ✔ Powerful use of binary search beyond simple searching ✔ Understanding index patterns in sorted arrays ✔ Time Complexity: O(log n) ✔ Space Complexity: O(1) --- 🔥 136 days of consistency — sharp logic beats brute force! #LeetCode #Day136 #BinarySearch #Arrays #Java #DSA #ProblemSolving #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