Two Best Non-Overlapping Events | Brute Force | Better | Leetcode 2054 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 128th Video of our Playlist "Arrays 1D/2D Search : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a good Array intervals based problem : Two Best Non-Overlapping Events | Brute Force | Better | Leetcode 2054 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Minimum Limit of Balls in a Bag | Brute Force | Better | Leetcode 2054 | codestorywithMIK
Company Tags : will update later
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Arrays/Intervals_Based_Qn/Two Best Non-Overlapping Events.cpp
Leetcode Link : https://leetcode.com/problems/two-best-non-overlapping-events
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
Approach-1: Brute Force (TLE)
Time Complexity: O(n^2)
Space Complexity: O(1)
This approach uses two nested loops to compare each event with every other event. For each pair of events, it checks whether they overlap (based on their start and end times) and calculates the maximum value possible by considering non-overlapping events. The solution simply checks every combination of two events, which leads to the quadratic time complexity. This approach is inefficient and leads to a time limit exceeded (TLE) error for large inputs.
Approach-2: Recursion + Memoization and Sorting
Time Complexity: O(n*logn) (Sorting) + O(n) for recursion with memoization
Space Complexity: O(n×3)≈O(n)
This optimized approach sorts the events first by their start time. Then, it uses recursion combined with memoization to explore all possible solutions. It also uses binary search (upper_bound) to efficiently find the next non-overlapping event. This reduces the need for nested loops and ensures that the solution can handle larger inputs. By memoizing results for overlapping subproblems, we avoid recalculating the same solutions multiple times. The overall time complexity is significantly improved to O(nlogn), making it suitable for larger inputs.
✨ Timelines✨
00:00 - Introduction
#MIK #mik #Mik
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik