Day 18 of #100DaysOfCode: #DSA: Learned the Merge Intervals Pattern Use it when you’re dealing with ranges/intervals in an array, especially when: - you need to merge overlapping intervals - you need to detect conflicts or overlaps - you are asked to insert a new interval Core Idea: - Sort intervals based on start time. - Compare current interval with the last merged interval. - If they overlap then merge them. - If not then add it as a new interval. #Problem: Solve Leetcode problem using this pattern - Merge Intervals(56) Time complexity: O(n logn) - Because we are doing sorting and sorting will take O(nlogn) time complexity in the worst case. If we talk about the overall time complexity then it is O(n logn) + O(n) where n is the length of intervals array. Space complexity: O(n) - Because we are using vector/array to store the result. And it will take O(n) in worst case if none of the intervals are overlapping. #DSA #Coding #LearnInPublic #CodingJourney
Merge Intervals Pattern for Array Ranges
More Relevant Posts
-
#Day42 Of #100DaysOfCode: #DSA: solve leetcode problem - Search a 2D Matrix II simple approach: - start from matrix[last_row][first_col] - check if matrix[row][col] > target then go up means row--; - else if matrix[row][col] < target then go right means col++; - else means matrix[row][col] == target -> return true; - int the last return false it will only run when the loop does't return Time: O(m + n) space: O(1) #DSA #Coding #Daily #Leetcode #CodingJourney #Learning
To view or add a comment, sign in
-
-
#Day41 of #100DaysOfCode: #DSA: Solve leetcode problem - Search a 2D Matrix(74) simple approach: Performing binary search twise: first time to find the row, then second time to find the element within that row. Time: O(log (M * N)) Space: O(1) #Coding #Daily #ProblemSoliving #Learning #CodingJourney #DSA
To view or add a comment, sign in
-
-
🚀 Day 11 of #LeetCodeConsistency Today I solved Number of Steps to Reduce a Number in Binary Representation to One 💻 This problem focuses on reducing a binary number to 1 using two operations: ✔️ If the number is even → divide by 2 ✔️ If the number is odd → add 1 A key insight was realizing that converting the binary string to an integer is unnecessary (and inefficient for large inputs). Instead, the problem can be solved optimally by traversing the binary string from right to left while simulating carry propagation, similar to binary addition. This allows us to count operations in a single pass without modifying the string. 🔎 What I learned today • How division by 2 in binary corresponds to pointer movement • Importance of carry-based simulation for big-number problems • A classic pattern applicable to string addition and bit manipulation questions ✅ Implemented an O(n) time and O(1) space solution ✅ Strengthened my understanding of binary simulation patterns 📌 Check out my solution here: https://lnkd.in/dzsegVhV Consistency compounds — excited to keep learning and improving every day 💪 #LeetCode #DSA #ProblemSolving #Coding #SoftwareEngineering #BitManipulation #100DaysOfCode
To view or add a comment, sign in
-
-
#Day520 of #500DaysOfDSA Topics and Learnings: #LinkedList, #Pointer Problems Re-revised: 140. #TUF+ : Insertion at the head of LL Approach: Used #pointers to solve this Complexity Analysis: TC: O(1) SC: O(1) #500DaysLeetCodeChallenge #500DaysLeetCode #DataStructures #Algorithms #ProblemSolving #DSA #LeetCode #TakeUForward #TUF+ #SoftwareDevelopment #ContinuousLearning #ProfessionalGrowth #Coding
To view or add a comment, sign in
-
-
#Day502 of #600DaysOfDSA Topics and Learnings: #LinkedList, #2Pointers Problems Re-revised: 122. #LeetCode #19 : Remove Nth Node From End of List Approach: Used #TwoPointers to solve this Complexity Analysis: TC: O(N) SC: O(1) #600DaysLeetCodeChallenge #600DaysLeetCode #DataStructures #Algorithms #ProblemSolving #DSA #LeetCode #TakeUForward #TUF+ #SoftwareDevelopment #ContinuousLearning #ProfessionalGrowth #Coding
To view or add a comment, sign in
-
-
#Day523 of #600DaysOfDSA Topics and Learnings: #Recursion Problems Re-revised: 143. #LeetCode #282 : Expression Add Operators Approach: Used #Recursion to solve this Complexity Analysis: TC: O(4^N) SC: O(N) #600DaysLeetCodeChallenge #600DaysLeetCode #DataStructures #Algorithms #ProblemSolving #DSA #LeetCode #TakeUForward #TUF+ #SoftwareDevelopment #ContinuousLearning #ProfessionalGrowth #Coding
To view or add a comment, sign in
-
-
Day 51/100 | DSA Journey — Sorting a Linked List Problem Solved: 1. LeetCode 148 - Sort List Concepts Strengthened: 1. Converting Linked List to array for sorting 2. Applying STL sort for value ordering 3. Rewriting sorted values back into list 4. Traversing linked list efficiently 5. Understanding trade-offs between approaches Approach Used: 1. Store all node values in a vector 2. Sort the vector 3. Traverse list again and overwrite values Time Complexity: O(n log n) Space Complexity: O(n) Key Learning: There are multiple ways to solve a problem. Optimal solution uses Merge Sort on Linked List (O(1) space), but understanding simpler approaches builds clarity first. Clarity > Premature optimization. #Day51 #100DaysOfDSA #LeetCode148 #LinkedList #Sorting #DSA #ProblemSolving #Consistency #gfg #coding #streak #grinding
To view or add a comment, sign in
-
-
#Day513 of #600DaysOfDSA Topics and Learnings: #LinkedList, #Pointers Problems Re-revised: 133. #TUF+ : Delete the element with value X Approach: Used #Pointers to solve this Complexity Analysis: TC: O(N) SC: O(1) #600DaysLeetCodeChallenge #600DaysLeetCode #DataStructures #Algorithms #ProblemSolving #DSA #LeetCode #TakeUForward #TUF+ #SoftwareDevelopment #ContinuousLearning #ProfessionalGrowth #Coding
To view or add a comment, sign in
-
-
#Day504 of #600DaysOfDSA Topics and Learnings: #LinkedList, #Pointers Problems Re-revised: 124. #LeetCode #2 : Reverse a LL Approach: Used #Pointers to solve this Complexity Analysis: TC: O(N) SC: O(1) #600DaysLeetCodeChallenge #600DaysLeetCode #DataStructures #Algorithms #ProblemSolving #DSA #LeetCode #TakeUForward #TUF+ #SoftwareDevelopment #ContinuousLearning #ProfessionalGrowth #Coding
To view or add a comment, sign in
-
-
#Day518 of #600DaysOfDSA Topics and Learnings: #LinkedList, #Pointers Problems Re-revised: 138. #TUF+ : Insertion at the tail of LL Approach: Used #Pointers to solve this Complexity Analysis: TC: O(N) SC: O(1) #600DaysLeetCodeChallenge #600DaysLeetCode #DataStructures #Algorithms #ProblemSolving #DSA #LeetCode #TakeUForward #TUF+ #SoftwareDevelopment #ContinuousLearning #ProfessionalGrowth #Coding
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