Insert Interval | Brute Force | Optimal | Google | Apple | codestorywithMIK

  Рет қаралды 8,878

codestorywithMIK

codestorywithMIK

Күн бұрын

This is our 32nd Video on our Array Playlist.
In this video we will try to solve a very very popular and good Qn "Insert Interval".
Interval Based Qns are often asked by Google.
We will do live coding after explanation and see if we are able to pass all the test cases.
Problem Name : Insert Interval
Company Tags : Google, Twitter, Microsoft, Apple, Amazon
My solutions on Github(C++ & JAVA) : github.com/MAZHARMIK/Intervie...
Leetcode Link : leetcode.com/problems/insert-...
My DP Concepts Playlist : • Roadmap for DP | How t...
My Graph Concepts Playlist : • Graph Concepts & Qns -...
My Recursion Concepts Playlist : • Introduction | Recursi...
My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
Subscribe to my channel : / @codestorywithmik
0:00 - Intro
0:33 - Understand Qn
4:08 - Brute Force
12:25 - Live Coding Brute Force
16:14 - Optimal
21:44 - Live Coding Optimal
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish

Пікірлер: 70
@OtakRajCodes
@OtakRajCodes Жыл бұрын
Thanks for the wonderful explanation!! For my fellow new leetcoder's struggling with java solution , here is the code with same logic : class Solution { public int[][] insert(int[][] intervals, int[] newInterval) { List res = new ArrayList(); if(intervals.lengthnewInterval[1]){ res.add(newInterval); res.add(interval); isUsed =true; } else if(!isUsed && interval[1]>=newInterval[0]){ //modify the newIndex if overlap is found newInterval[0] = Math.min(interval[0],newInterval[0]); newInterval[1] = Math.max(interval[1],newInterval[1]); }else{ //if current interval does not overlap with newInterval res.add(interval); } } //if the newinterval has not been inserted -> insert at the end. if(!isUsed){ res.add(newInterval); } return res.toArray( new int[res.size()][]); } }
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you so much for providing JAVA version. Pinning this comment
@nagmakhan672
@nagmakhan672 Жыл бұрын
Thanks a lot for java
@Krishna-mz2uk
@Krishna-mz2uk Жыл бұрын
This is better version of code in JAVA similar to video class Solution { public int[][] insert(int[][] intervals, int[] newInterval) { List res=new ArrayList(); int n=intervals.length; int i=0; while(i
@codestorywithMIK
@codestorywithMIK Жыл бұрын
I want to thank all of you for providing JAVA version
@ayusshrathore
@ayusshrathore Жыл бұрын
Where were you before? How come your channel isn't being recommended for such questions. On-point explanation. Thanks, man! And, is it possible if you could code in java too? Would help a lot of viewers.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot Ayush for your appreciation. Actually i have not experience in Java but I will soon try adding java code too Thanks again for watching ❤️
@adityatripathi9045
@adityatripathi9045 Ай бұрын
i was having problem in how to tell whether the intervals are overlapping or not ..but now its clear🙌
@NatureLover-oq6uc
@NatureLover-oq6uc Жыл бұрын
GREAT EXPLANATION.
@user-ub2is4rs4x
@user-ub2is4rs4x 4 ай бұрын
Legend for a reason 👌🏻👌🏻👌🏻
@ayushjain386
@ayushjain386 Жыл бұрын
Thank you for such wonderful videos
@wearevacationuncoverers
@wearevacationuncoverers Жыл бұрын
Your explanation is exceptional.
@animesh414
@animesh414 Жыл бұрын
Your explanation is great.
@turing_machine544
@turing_machine544 Жыл бұрын
Thanks Bhaiya for wonderful explanation..
@philosphize
@philosphize Жыл бұрын
Thanks , Bruteforce solution is also submitted successfully
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Awesome 👏
@AnjuGupta-sz1uk
@AnjuGupta-sz1uk 4 ай бұрын
Bhaiya your explanation is best😄
@harshtiwari3928
@harshtiwari3928 Жыл бұрын
Thanks coded myself🔥🔥
@oqant0424
@oqant0424 Жыл бұрын
what an explanation✨
@rohitsoni5491
@rohitsoni5491 4 ай бұрын
Bro this was helpful :)
@souravjoshi2293
@souravjoshi2293 Жыл бұрын
Thanks a lot man
@altafmazhar7762
@altafmazhar7762 Жыл бұрын
Good Job Bro keep Going
@k-CE-OmkarPathak
@k-CE-OmkarPathak 4 ай бұрын
Thank you !!
@niteshk0487
@niteshk0487 Жыл бұрын
God or wot❤✅
@OIAOa
@OIAOa 4 ай бұрын
Tq bhaiya ❤
@iamnoob7593
@iamnoob7593 18 күн бұрын
Thank u
@03_utpallucky40
@03_utpallucky40 5 күн бұрын
We can use stack as well na ??Jabvi hme prev chj ki jrrt pre aap ne hi btaya tha mtlb we can think of stack too❤️.
@nagmakhan3165
@nagmakhan3165 Жыл бұрын
Made it a cakewalk
@gauravbanerjee2898
@gauravbanerjee2898 4 ай бұрын
Thanks a lot bhaiya ❤❤
@codestorywithMIK
@codestorywithMIK 4 ай бұрын
Most welcome
@shabananoor9423
@shabananoor9423 Жыл бұрын
Damn this looks so easy now
@ugcwithaddi
@ugcwithaddi 4 ай бұрын
🔥🔥🔥👌🏻
@udaytewary3809
@udaytewary3809 Жыл бұрын
You are really great bhaiya just loved your way of explanation and you won't believe that I was also thinking about the same solution of using an array but don't having clear idea how to proceed further but after watching you I got clear how to proceed further. One doubt bhaiya in your first approach where you were erasing element in that for while loop you write i< intervals.size instead of n I am not able to understand that part can you please explain that And also wanted to ask one thing bhaiya I have never seen this question and while solving the optimise approach of using array comes to my mind is it good or bad for interview perspective
@codestorywithMIK
@codestorywithMIK Жыл бұрын
It’s good that the approach came to your mind ❤️💪 I am using intervals.size instead of n because when i erase an element from vector, it’s size is no longer n, so it’s safe to use intervals.size() instead of n because it’s changing
@shabananoor9423
@shabananoor9423 Жыл бұрын
Made easy
@jyotishmoydeka6804
@jyotishmoydeka6804 Жыл бұрын
Bhaiya thora sa arrows need to burst ballons wale ke type hoga na? and wonderfull explanantion as usual!!❤‍🔥❤‍🔥
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Yes falls on the same type. Thanks a lot for your appreciation
@Raj-wx8fi
@Raj-wx8fi Ай бұрын
sir ek chij samjh nhi ayi ki optimal solution me agar end me jo bache hai wo sb daal de rhe ans me to agar aage koi interval merge krne wala hua to wo to bach gaya fir??
@Krishna-mz2uk
@Krishna-mz2uk Жыл бұрын
.insert() method for arrays is available in c++ is there any similar method to inert() in array in java
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Not sure about Java but this can help i guess : The insertElementAt() method of Java Vector class is used to insert the specified object as a component in this vector at the specified index
@piyushacharya7696
@piyushacharya7696 Жыл бұрын
Bro, I could also code it up but I used for loop so my code was failing all the test cases. but now I know the reason.😅😅
@shreyash_17_
@shreyash_17_ 5 ай бұрын
DAY - 8 16/02/2024 STARTED WITH LEC 32 .
@nitinsingh1602
@nitinsingh1602 Ай бұрын
i submitted the 1st approach of brute force , it gets accepted without showing tle on leetcode
@harshitrajput7340
@harshitrajput7340 5 ай бұрын
Solved myself after watching lecture 31 here is c++ code class Solution { public: vector insert(vector& intervals, vector& newInterval) { vectorresult; int n = intervals.size(); intervals.push_back({newInterval}); sort(intervals.begin(),intervals.end()); vectorprev = intervals[0]; for(int i = 1;iprev_ep){ // no overlap result.push_back(prev); prev = intervals[i]; } else{ prev[0]= min(prev_sp,curr_sp); prev[1] = max(prev_ep,curr_ep); } } result.push_back(prev); return result; } }; ❤❤
@pritishpattnaik4674
@pritishpattnaik4674 Жыл бұрын
Apne ek interval wala problem solve karwaya tha , eie uske baad easy lag raha hai
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Awesome 💝💪
@pritishpattnaik4674
@pritishpattnaik4674 Жыл бұрын
@@codestorywithMIK also I learnt the vector insert , thanks for everthing
@manojyadav6967
@manojyadav6967 Жыл бұрын
Sir , How you are able to use this Leetcode UI , Beacause in my Windows Laptop it is changed and is very bad
@codestorywithMIK
@codestorywithMIK Жыл бұрын
You can change the theme (beta version) and go back to old version from your account icon in top right corner
@girikgarg8
@girikgarg8 Жыл бұрын
class Solution { public: vector insert(vector& intervals, vector& newInterval) { vector res; int n = intervals.size(), i = 0; while(i < n && intervals[i][1] < newInterval[0]) res.push_back(intervals[i++]); while(i < n && intervals[i][0]
@satyamkumaryadav1560
@satyamkumaryadav1560 Жыл бұрын
bro can you upload a series on binary trees, like where you teach how to approach a problem
@codestorywithMIK
@codestorywithMIK Жыл бұрын
There is already a playlist on Binary Tree from me - kzbin.info/aero/PLpIkg8OmuX-K23LhcamOcDlTBisiNJy5E Hope this helps
@Raj10185
@Raj10185 Жыл бұрын
More simple code to understand :- vector ans; int i; for( i = 0 ; i < intervals.size();i++) { int currstart = intervals[i][0]; int currend = intervals[i][1]; if(newinterval[1] < currstart) { ans.push_back(newinterval); ans.insert(ans.end(),intervals.begin(),intervals.end()); return ans;} else if (newinterval[0] > currend ) { ans.push_back(intervals[i]); } else { newinterval[0] = min( newinterval[0] , currstart); newinterval[1] = max(newinterval[1],currend); } } ans.push_back(newinterval); return ans;
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Awesome. Thanks for sharing
@kumarsaurabh5449
@kumarsaurabh5449 Жыл бұрын
Overlapping Intervals sir is question pai bhi ake video bana do
@kumarsaurabh5449
@kumarsaurabh5449 Жыл бұрын
you explanation is amazing👌👌👌
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Sure Saurabh. Soon Thanks for suggesting
@Krishna-mz2uk
@Krishna-mz2uk Жыл бұрын
Bro Voice ko toda increase karo
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Noted. Thanks a lot for your feedback
@AmandeepSingh-uq3wp
@AmandeepSingh-uq3wp Жыл бұрын
Mera toh brute force hi accept hogaya aesa kyun hua 🤔 aapka TLE aa raha 🤔
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Can you share your code please ?
@AmandeepSingh-uq3wp
@AmandeepSingh-uq3wp Жыл бұрын
@@codestorywithMIK It's same as yours class Solution { public: vector insert(vector& intervals, vector& newInterval) { int i = 0; while(i
@codestorywithMIK
@codestorywithMIK Жыл бұрын
I see. Strange. Never mind 😇 Thanks a lot for sharing
@piyushacharya7696
@piyushacharya7696 Жыл бұрын
Yeah, (10^4)^2 should be 10^8 which should work. but why MIK soln got TLE😅😅
@akashgoyal3573
@akashgoyal3573 4 ай бұрын
use good quality mike your sound is very low
@codestorywithMIK
@codestorywithMIK 4 ай бұрын
Yes old videos had audio issue. New videos have been ensured good audio ❤️🙏
@AnandKumar-kz3ls
@AnandKumar-kz3ls Жыл бұрын
bro when you sleep ??
@souravjoshi2293
@souravjoshi2293 Жыл бұрын
I have the same Qn lol
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Had a hectic Sunday. Else i sleep early 🙂
Merge Overlapping Intervals | Brute, Optimal with Precise TC analysis
22:35
НРАВИТСЯ ЭТОТ ФОРМАТ??
00:37
МЯТНАЯ ФАНТА
Рет қаралды 1,6 МЛН
Beautiful gymnastics 😍☺️
00:15
Lexa_Merin
Рет қаралды 14 МЛН
DAD LEFT HIS OLD SOCKS ON THE COUCH…😱😂
00:24
JULI_PROETO
Рет қаралды 14 МЛН
57. Insert Interval | Greedy | LeetCode daily challenge | C++ | Hindi
12:53
VICKY KAUSHAL REACTS TO VICKY KAUSHAL MEMES ft. VICKY KAUSHAL
26:42
Tanmay Bhat
Рет қаралды 5 МЛН
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 356 М.
Crowdstruck (Windows Outage) - Computerphile
14:42
Computerphile
Рет қаралды 117 М.
Real reason behind Microsofts blue screen of Death
9:28
Hitesh Choudhary
Рет қаралды 110 М.
НРАВИТСЯ ЭТОТ ФОРМАТ??
00:37
МЯТНАЯ ФАНТА
Рет қаралды 1,6 МЛН