🚀 Day 39 / 100 | Non-overlapping Intervals -Intuition: -The goal is to remove the minimum number of intervals so that the remaining intervals do not overlap. -The idea is to always keep the interval that ends earlier because it leaves more space for future intervals. -If an interval overlaps with the previous selected interval, remove it. -Approach: O(n log n) -Sort all intervals based on their ending time. -Initialize last to track the end of the last selected interval. -Traverse through the intervals starting from the second interval. -If the current interval's start is less than the last end, it means overlap exists, remove the interval.(count++) -Otherwise, update last end to the current interval’s end. -Return the count of removed intervals. -Complexity: Time Complexity: O(n log n) Space Complexity: O(1) #100DaysOfCode #Java #DSA #LeetCode #Greedy
Non-Overlapping Intervals Java Solution
More Relevant Posts
-
Day 12/100 – LeetCode Challenge Problem: Middle of the Linked List Today’s problem focused on finding the middle node of a singly linked list. Approach: Used the Two-Pointer Technique (Slow & Fast pointers). slow moves one step at a time fast moves two steps at a time When fast reaches the end of the list, slow will be at the middle node Complexity: Time: O(n) Space: O(1) Concepts Practiced: Linked List traversal Two-pointer technique Efficient single-pass solution #100DaysOfCode #LeetCode #DSA #Java #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 52/100 Completed ✅ 🚀 Solved LeetCode – Merge Intervals (Java) ⚡ Implemented an interval merging approach by first sorting intervals based on their start times and then traversing them to combine overlapping ranges. 🧠 Used comparison logic to detect overlaps and update interval boundaries, ensuring that all overlapping intervals are merged efficiently. This approach avoids redundant checks and processes the intervals in a single pass after sorting. 💯 Strengthened understanding of interval problems, sorting strategies, and greedy traversal techniques commonly used in real-world scheduling and timeline merging scenarios. Profile: https://lnkd.in/gaJmKdrA #LeetCode #100DaysOfCode #Java #DSA #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
Day 7 – #50DaysLeetCodeChallenge Today, I solved the Largest Number problem. Problem Statement: Given a list of non-negative integers, arrange them such that they form the largest possible number. Since the result can be very large, return it as a string. Example: - [10, 2] → "210" - [3, 30, 34, 5, 9] → "9534330" Approach I Used – Custom Sorting: This problem is not about normal sorting; it’s about deciding the correct order of numbers based on concatenation. 1. Convert all integers into strings. 2. Sort the array using a custom comparator. 3. For two numbers a and b, compare: "ab" vs "ba". If "ba" is larger, place b before a. 4. Join all strings to form the final result. #LeetCode #Java #DSA #CodingChallenge #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 35 — LeetCode Progress (Java) Problem: Divide Players Into Teams of Equal Skill Required: Pair players so that each team has the same total skill. Return the sum of chemistry (product of paired skills) or -1 if not possible. Idea: Sort the array and use two pointers. If teams must have equal total skill, the smallest and largest values must pair together to maintain a constant sum. Approach: Sort the skill array. Set left = 0, right = n - 1. Compute target sum = skill[left] + skill[right]. While left < right: If skill[left] + skill[right] ≠ target, return -1. Add skill[left] × skill[right] to result. Move both pointers inward. Return total chemistry. Time Complexity: O(n log n) Space Complexity: O(1) (excluding sorting space) #LeetCode #DSA #Java #TwoPointers #Greedy #Sorting #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 47 / 100 – LeetCode Challenge Solved Remove Nth Node From End of List (Linked List problem). 💡 Key Idea: Used the Two Pointer (Fast & Slow) technique. Move the fast pointer n steps ahead, then move both pointers together until fast reaches the end. This helps identify the node just before the one to remove. ⚡ Result: ✅ Runtime: 0 ms (Beats 100%) ✅ Testcases Passed: 208 / 208 📚 Concepts Practiced: Linked Lists Two Pointer Technique Dummy Node for edge cases Consistency > Perfection. One problem closer to the goal! 💪 #Day47 #100DaysOfCode #LeetCode #DSA #Java #CodingJourney #LinkedList
To view or add a comment, sign in
-
-
Day 22/30 – Remove Nth Node From End of List Solved a classic Linked List problem today. Approach: • Use Two Pointers (Fast & Slow) • Move fast pointer n+1 steps ahead • Move both pointers until fast reaches the end • Slow pointer will be right before the node to remove Time Complexity: O(n) Space Complexity: O(1) Key concept: Two-pointer technique with a dummy node. #30DaysOfDSA #Java #LinkedList #CodingChallenge
To view or add a comment, sign in
-
-
💻 LeetCode Practice – Day 15 Solved Valid Anagram (Problem 242) today. 📌 Problem: Given two strings s and t, return true if t is an anagram of s, otherwise return false. 🧠 Approach: • Check if both strings have the same length. • Use a frequency array to count characters. • Increment for s and decrement for t. • If all values become zero, the strings are anagrams. #LeetCode #Java #DSA #CodingPractice
To view or add a comment, sign in
-
-
🚀 Day 38 of #100DaysOfCode 🌱 Topic: Linked List / Recursion ✅ Problem Solved: LeetCode 24 – Swap Nodes in Pairs 🛠 Approach: Used a recursive approach to swap every two adjacent nodes in the linked list. If the list has 0 or 1 node, return it directly (base case). Store the second node (head.next) as a temporary node. Recursively swap the remaining list starting from temp.next. Adjust pointers so the second node becomes the new head of the pair. Connect the swapped pair with the recursively processed list. This swaps nodes without modifying their values, only changing pointers. #100DaysOfCode #Day38 #DSA #LinkedList #Recursion #LeetCode #Java #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 35 - Min Stack Designed a stack that supports push, pop, top, and retrieving the minimum element in constant time. Used an auxiliary stack to track the minimum value at each stage, ensuring efficient updates during push and pop operations. Time Complexity: O(1) for all operations #Day35 #LeetCode #Java #Stack #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Solved LeetCode 2839 – Check if Strings Can be Made Equal With Operations I today. In simple terms, we are given two strings and allowed to swap characters only at positions that are 2 indices apart (like index 0 with 2, 1 with 3). So instead of trying all swaps, the idea is to separate characters at even and odd positions and check if both strings have the same characters in those positions. If the frequency of characters matches for even and odd indices separately, then the strings can be made equal. A simple yet interesting problem that improves thinking around patterns and constraints. #LeetCode #DSA #Java #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