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

ความคิดเห็น • 81

  • @VedaVyasaa
    @VedaVyasaa ปีที่แล้ว +24

    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. 💌💌

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +3

      Thank you so much for your wishes ❤️
      Hope it reaches more people soon.

    • @Momentsofmagic28
      @Momentsofmagic28 ปีที่แล้ว

      Indeed

  • @amanpratapsingh3256
    @amanpratapsingh3256 2 หลายเดือนก่อน +5

    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!!

  • @prathamtetgure2963
    @prathamtetgure2963 ปีที่แล้ว +7

    Ur Calm Voice Explaination is THE BEST

  • @prem_kumar
    @prem_kumar 2 หลายเดือนก่อน +8

    who is here after robot collision video?

    • @gui-codes
      @gui-codes 2 หลายเดือนก่อน +1

      Me too bro😅

    • @Infinite_Mainak
      @Infinite_Mainak 2 หลายเดือนก่อน +1

      Uss bro😂

    • @EB-ot8uu
      @EB-ot8uu 2 หลายเดือนก่อน +1

      I am here too 😅

  • @DurgaShiva7574
    @DurgaShiva7574 ปีที่แล้ว +1

    the way u teach is mind blowing, those who run paid courses are nothing in front of explanation u give, hats off 2 u

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Thank you so much
      You made my day 😇🙏

  • @rahulmandal3018
    @rahulmandal3018 7 หลายเดือนก่อน +3

    Such an underrated channel man!.... Never seen this type of explanation. Loved your content bhai♥

    • @codestorywithMIK
      @codestorywithMIK  7 หลายเดือนก่อน

      It means a lot Rahul
      Thank you for your kind words ❤️❤️🙏🙏

  • @aws_handles
    @aws_handles 8 หลายเดือนก่อน +1

    Dope explanation . Most underrated channel ❤

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 ปีที่แล้ว +2

    Intuition and explanation is superb 👌. your channel becomes most popular in dsa

  • @priyanshugoutam1223
    @priyanshugoutam1223 11 หลายเดือนก่อน +1

    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

    • @codestorywithMIK
      @codestorywithMIK  11 หลายเดือนก่อน +1

      So glad to know. Thank you for watching 😇🙏
      Today’s POTD now being uploaded

  • @UtkarshPatel-v9o
    @UtkarshPatel-v9o ปีที่แล้ว +2

    nice explanation

  • @AnjuGupta-sz1uk
    @AnjuGupta-sz1uk 8 หลายเดือนก่อน +2

    learnt best way of using vector as stack

  • @itsaryanb9316
    @itsaryanb9316 6 หลายเดือนก่อน +1

    Perfectly Explained, Thank You !!

  • @souravjoshi2293
    @souravjoshi2293 ปีที่แล้ว +1

    Crystal clear like always.

  • @venomdhruv2220
    @venomdhruv2220 9 หลายเดือนก่อน +5

    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

    • @HammyHues
      @HammyHues 2 หลายเดือนก่อน +1

      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 , '-'

  • @kishan.17
    @kishan.17 ปีที่แล้ว +1

    thank soo much bro explaination quality is next level ,super explaination🥰

  • @mohd.tabishkhan4868
    @mohd.tabishkhan4868 8 หลายเดือนก่อน +1

    Epic solution

  • @vikrant2766
    @vikrant2766 ปีที่แล้ว +1

    Short , sweet and to the point explaination no cap❤

  • @dprsd042
    @dprsd042 ปีที่แล้ว +1

    Amazing explanation about the way you think of the approach to solve the question 💯🔥

  • @anshumaan1024
    @anshumaan1024 5 หลายเดือนก่อน +1

    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

  • @Rohan-o8b
    @Rohan-o8b ปีที่แล้ว +1

    may god bless with lots of health and wealth bro!! you're awesome af

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Thank you so much
      It means a lot ❤️❤️
      I wish the same for you all 😇

  • @anuppatankar4294
    @anuppatankar4294 ปีที่แล้ว +2

    Great Video 😍

  • @shambhavisoni2297
    @shambhavisoni2297 ปีที่แล้ว +2

    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

    • @shambhavisoni2297
      @shambhavisoni2297 ปีที่แล้ว

      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]

    • @ashishdhal4614
      @ashishdhal4614 ปีที่แล้ว +1

      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

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Yesss

    • @shambhavisoni2297
      @shambhavisoni2297 ปีที่แล้ว

      @@codestorywithMIK time complexity will still be same?

    • @AyushRaj-we2og
      @AyushRaj-we2og ปีที่แล้ว

      I did the same way :)

  • @kartikrameshchavan6662
    @kartikrameshchavan6662 ปีที่แล้ว +2

    Op 👍

  • @anubhavdeepankar6681
    @anubhavdeepankar6681 3 หลายเดือนก่อน +2

    this solution is the best

  • @perspectives1827
    @perspectives1827 9 หลายเดือนก่อน +1

    Thankyou so much for explaining every why clearly

    • @codestorywithMIK
      @codestorywithMIK  9 หลายเดือนก่อน

      Glad it was helpful! ❤️🙏

  • @ayanahmed2221
    @ayanahmed2221 ปีที่แล้ว +1

    Best explaination 👏

  • @amitkumarchoudhary9008
    @amitkumarchoudhary9008 ปีที่แล้ว +2

    Bhaiya u r awesome !!

  • @codeandtalk6
    @codeandtalk6 ปีที่แล้ว +1

    Solved it on my own ❤❤❤

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +6

      I am the happiest when I hear this in my comment section.
      Together we all are growing 💪💪💪

  • @asmitsrivastava924
    @asmitsrivastava924 10 หลายเดือนก่อน +2

    your videos are very helpful

    • @codestorywithMIK
      @codestorywithMIK  10 หลายเดือนก่อน

      Thank you so much ❤️❤️❤️

  • @wearevacationuncoverers
    @wearevacationuncoverers ปีที่แล้ว

    Made it too easy to understand. Thanks a lot

  • @MohammedHasmi577
    @MohammedHasmi577 หลายเดือนก่อน

    Nice video sir

  • @good114
    @good114 ปีที่แล้ว +1

  • @DurgaShiva7574
    @DurgaShiva7574 ปีที่แล้ว

    please if possible start a playlist on LLD for experienced folks.

  • @BiswajitDas-lk7pp
    @BiswajitDas-lk7pp 7 หลายเดือนก่อน

    Amazing Explainaton 💯💯 ThankYou

  • @AyushRaj-we2og
    @AyushRaj-we2og ปีที่แล้ว +1

    Understood!😇

  • @pryansh_
    @pryansh_ 11 หลายเดือนก่อน +1

    it was really helpful.

    • @codestorywithMIK
      @codestorywithMIK  11 หลายเดือนก่อน

      Thank you for watching 😇

  • @DevOpskagyaan
    @DevOpskagyaan 10 หลายเดือนก่อน

    There is only one MIK and there will be only one. Never seen this teaching level before

  • @VA04
    @VA04 7 หลายเดือนก่อน

    i say only one thing thanks man.

  • @satyamgupta4808
    @satyamgupta4808 11 หลายเดือนก่อน

    nice bro

  • @ultimatequora
    @ultimatequora ปีที่แล้ว +1

    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.

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      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.

  • @shivansh2870
    @shivansh2870 ปีที่แล้ว +1

    jai ho mik baba ki

  • @dhairyachauhan6622
    @dhairyachauhan6622 ปีที่แล้ว +1

    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.

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +2

      Don't worry, initially it happens. But with more practice our speed will increase.
      Keep practicing.

  • @Bibhukalyan_iitkgp_21
    @Bibhukalyan_iitkgp_21 ปีที่แล้ว +1

    Sir Bitmask dp padha dijiye plzzzzzzzzzz

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Definitely it will be covered in this - th-cam.com/play/PLpIkg8OmuX-JhFpkhgrAwZRtukO0SkwAt.html

  • @priyadarshanghoshhazra7648
    @priyadarshanghoshhazra7648 ปีที่แล้ว +1

    Can this be done without extra space?

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      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

  • @VaibhavSutar-xm3cn
    @VaibhavSutar-xm3cn 19 วันที่ผ่านมา

    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

  • @floatingpoint7629
    @floatingpoint7629 ปีที่แล้ว +1

    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;
    };

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Thanks a lot for sharing your code 🙏❤️

  • @Momentsofmagic28
    @Momentsofmagic28 ปีที่แล้ว

    My one stop solution to all problems - codestorywithMIK