Asteroid Collision | Intuition | Dry Run | Leetcode-735 | Uber | Lyft | Explanation ➕ Live Coding
ฝัง
- เผยแพร่เมื่อ 20 ก.ย. 2024
- Hi everyone, this is the 12th video of our Stack playlist.
In this video we will try to solve a very good and famous stack problem "Asteroid Collision". (Leetcode-735)
We will write very easy and clean code with intuition building and understanding each line of code.
We will do live coding after explanation and see if we are able to pass all the test cases.
Problem Name : Asteroid Collision
Company Tags : Uber, Lyft
My solutions on Github : github.com/MAZ...
Leetcode Link : leetcode.com/p...
My GitHub Repo for interview preparation : github.com/MAZ...
Subscribe to my channel : / @codestorywithmik
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish
you're really doing a great job man. Helping out a lot of students. Hats off and stay consistent. Your channel will surely be a success. 💌💌
Thank you so much for your wishes ❤️
Hope it reaches more people soon.
Indeed
After striver i find you who visualise the algorithm in such detail....hats off to you ....for putting such long explanation videos....keep up the good work man!!
Ur Calm Voice Explaination is THE BEST
It means a lot 😇❤️
who is here after robot collision video?
Me too bro😅
Uss bro😂
I am here too 😅
the way u teach is mind blowing, those who run paid courses are nothing in front of explanation u give, hats off 2 u
Thank you so much
You made my day 😇🙏
Such an underrated channel man!.... Never seen this type of explanation. Loved your content bhai♥
It means a lot Rahul
Thank you for your kind words ❤️❤️🙏🙏
Dope explanation . Most underrated channel ❤
Intuition and explanation is superb 👌. your channel becomes most popular in dsa
Thank you so much 😇🙏
did it on my own but watched the video till the end and improved my code thank you , also I have completed your stacks playlist now
So glad to know. Thank you for watching 😇🙏
Today’s POTD now being uploaded
nice explanation
learnt best way of using vector as stack
Perfectly Explained, Thank You !!
Crystal clear like always.
what if the asteroids array also contains 0 because on coding ninjas the same question is there but it also has 0 as input in that case the code is giving error for the testcases
As per the question, 0 is not valid. As the values in array represent Size, So size can never be zero. ( sign represent directions , '+' -> right , '-'
thank soo much bro explaination quality is next level ,super explaination🥰
Thanks a lot 😇🙏
Epic solution
Short , sweet and to the point explaination no cap❤
Thanks a lot Vikrant 😇❤️🙏
Amazing explanation about the way you think of the approach to solve the question 💯🔥
Thank you 🙌
TC using vector, O(N^2) nhi hoga ? 🤔🤔
kyoki pop_back() krne ke baad vector resize bhi toh hoga, which will take O(N) operation
may god bless with lots of health and wealth bro!! you're awesome af
Thank you so much
It means a lot ❤️❤️
I wish the same for you all 😇
Great Video 😍
in collision case,
instead of taking sum can't we just check if top is greater than arr[i] we don't need to do anything.
if top
like this
class Solution {
public:
vector asteroidCollision(vector& asteroids) {
stack st;
st.push(asteroids[0]);
for(int i=1;i=0 && st.top()>=0) || (asteroids[i]
Yes we can do it in a 2n time if stack is monotonous keep appending if there is a change use a while loop to pop
Yesss
@@codestorywithMIK time complexity will still be same?
I did the same way :)
Op 👍
this solution is the best
Thankyou so much for explaining every why clearly
Glad it was helpful! ❤️🙏
Best explaination 👏
Thanks a lot 😊
Bhaiya u r awesome !!
Thank you Amit 😇🙏
Solved it on my own ❤❤❤
I am the happiest when I hear this in my comment section.
Together we all are growing 💪💪💪
your videos are very helpful
Thank you so much ❤️❤️❤️
Made it too easy to understand. Thanks a lot
Nice video sir
❤
please if possible start a playlist on LLD for experienced folks.
Amazing Explainaton 💯💯 ThankYou
Understood!😇
it was really helpful.
Thank you for watching 😇
There is only one MIK and there will be only one. Never seen this teaching level before
i say only one thing thanks man.
🙏😇
nice bro
Kindly tell if love babbar sheet 450 is enough or if I should do more ,also suggest what more I should do .
I am preparing for google summer intern 2023 program.
Hi,
Actually i have never solved from any sheet.
But if that list help you revise and has all tooic, then it should be good.
jai ho mik baba ki
🙏🙏❤️❤️😇😇
i solved this on my own but took abt 1hr 😞😞. I always take about 1hr -2hrs hence feel demotivated coz you only get 35-45 min in an interview. How do i overcome this.
Don't worry, initially it happens. But with more practice our speed will increase.
Keep practicing.
Sir Bitmask dp padha dijiye plzzzzzzzzzz
Definitely it will be covered in this - th-cam.com/play/PLpIkg8OmuX-JhFpkhgrAwZRtukO0SkwAt.html
Can this be done without extra space?
It means we want to modify the input given.
It can be done but it will be O(n^2) because you need to travel back to vector again and again in case collision happens. Also the size of vector will keep on changing as you delete elements
var asteroidCollision = function(asteroids) {
let stack = []
for(let i=0;i (stack[stack.length-1] || 0)){
stack.push(asteroids[i])
}
}
}else{
stack.push(asteroids[i])
}
}
return stack
};
i tried by myself
thanks for the explanation. here is my solution:
/**
* @param {number[]} asteroids
* @return {number[]}
*/
var asteroidCollision = function (asteroids) {
// 5 ----> positive means right
// negative means left 5----> positive positive does not collide
// 0) {
a = 0;
break; // the asteriod on stack was bigger then the incoming one
}
else {
st.pop();
a = 0;
break;
}
}
if (a != 0) st.push(a);
}
return st;
};
Thanks a lot for sharing your code 🙏❤️
My one stop solution to all problems - codestorywithMIK