Astroid Collision

Sdílet
Vložit
  • čas přidán 19. 03. 2020
  • For business inquiries email partnerships@k2.codes SOCIAL
    ----------------------------------------------------------------------------------------------------------------
    Instagram: / kevinnaughtonjr
    Twitter: / kevinnaughtonjr
    Patreon: / kevinnaughtonjr
    Merch: teespring.com/stores/kevin-na...
    GitHub: github.com/kdn251
    MUSIC
    ----------------------------------------------------------------------------------------------------------------
    kanye west ft. lil pump - "i love it" (lofi remix by ofey) by ofey
    / i-love-it
  • Věda a technologie

Komentáře • 71

  • @KevinNaughtonJr
    @KevinNaughtonJr  Před 4 lety +10

    LYFT > UBER FIGHT ME IN THE COMMENTS BELOW
    instagram: instagram.com/kevinnaughtonjr/
    twitter: twitter.com/KevinNaughtonJr
    patreon: www.patreon.com/KevinNaughtonJr
    merch: teespring.com/stores/kevin-naughton-jrs-store

    • @varungupta2045
      @varungupta2045 Před 4 lety +9

      I live in India, we don't have lyft here. Case closed. 😂

  • @albertreyes2167
    @albertreyes2167 Před 4 lety +21

    I was never interviewed by lyft nor uber. I just started driving after background check 24 hours later

  • @lings628
    @lings628 Před 4 lety +1

    Thank you very. much. I like how to justify which data structure to use with some explanation, instead of just saying let's go ahead and use a stack for this problem. Huge fan of your channel. Keep up the fantastic work.

  • @jak0495
    @jak0495 Před 4 lety +10

    Lyft's most asked question is "how many coupons will it take to get someone to use lyft over uber?"

  • @surendra9935
    @surendra9935 Před 4 lety +8

    Oh my gosh, I have to learn a lot from you...Lots of Determination, Dedication, Discipline. You are consistent on what you are doing and there is no Friday nights fun. Great dude keep it going, I will follow you 🤗

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 4 lety

      Surendra thanks really appreciate the kind words and your support!!!

  • @saravanansarangan7035
    @saravanansarangan7035 Před 4 lety

    Great explanation Kevin!

  • @bambingbang
    @bambingbang Před 4 lety +1

    Awesome bro! It is really helpful for me to learn how to explain our solution to our interviewer!

  • @brijeshtiwari1357
    @brijeshtiwari1357 Před 3 lety +1

    Thanks man, It was seriously helpful :)

  • @rohitjaiswal4121
    @rohitjaiswal4121 Před 4 lety

    Please make a series on Uber and Lyft interview questions! Thanks for your efforts. You're doing great!

  • @mandeepbahal23
    @mandeepbahal23 Před 4 lety

    Would you do basic calculator I, II and III from leetcode

  • @ashishsingh-ty6kf
    @ashishsingh-ty6kf Před 4 lety +2

    i am not able to understand if you are only pushing positive value in the stack than why checks for negative in the stack?

  • @santasingh9045
    @santasingh9045 Před 3 lety

    great solution Kevin!

  • @JM_utube
    @JM_utube Před 4 lety +1

    using a stack is pretty intuitive, but the nuances are a little complicated. this deserves medium difficulty because of the repeated collisions from a new asteroid. good job on this video.

  • @joseph615
    @joseph615 Před 4 lety +1

    What is the difference between stack.push() and stack.add()?

  • @SomeshwarJ
    @SomeshwarJ Před rokem

    I just amazed for this simple solution 😃

  • @kitch3876
    @kitch3876 Před 2 lety

    Heya, no idea if you do this already or not but it would be really helpful to go over space and time complexity as well at the end :) Thanks for the video!

  • @chickendolo4437
    @chickendolo4437 Před 4 lety +12

    How do you come up with solutions to the hard or medium questions on leetcode? And keep it going dude ur channel is amazing 😊.

  • @darthvader_
    @darthvader_ Před 3 lety

    Haha! The sound at the last

  • @rjose705
    @rjose705 Před 4 lety +5

    subscribed to you! I like interview questions on my timeline and i love how your channel is dedicated to this. Also can u answer my other comment.

  • @N1KH1L_777
    @N1KH1L_777 Před 4 lety +5

    OMG I was literally on Lyft's questions and was doing this.. lol. Thanks Kevin. Can you also do Oracle's most asked question - #425 - Word Squares (hard)? Thanks in advance man

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 4 lety +4

      Nikhil Mathur haha no way that’s amazing I’ll put it on my list

  • @annawilson3824
    @annawilson3824 Před 2 lety

    Thanks for the video! All great, regarding the final part, is it just me or the explanation why we need 'remaining' array populated backwards was kind of unclear? In Python, we would just simply return stack. Here, we populate the 'remaining' array from the end since stack returns items in this order: last, last-1, last-2, so to convert it into remaining, we also start with populating last item of remaining, then last-1, etc.

  • @mostinho7
    @mostinho7 Před 4 lety +4

    When you asked us to pause the video and think of a solution, I thought of solving this by starting from the left to right and detecting the first collision (the first positive asteroid that is followed by a negative one), then we “collide them”, see which one survives and pass the array after the collision recursively to the same function. With the base condition being that we detect no more collisions in the array. (Or a for loop instead of recursion to save on memory of call stack)
    I wanted to ask you, first is this a crap solution? And second the time complexity of such solution would be O(n^2)?

    • @neslzkusfep
      @neslzkusfep Před 4 lety

      You're right. The time complexity is definitely O(n^2) cause Kevin is using a nested loop.

    • @mannyruiz7880
      @mannyruiz7880 Před rokem

      @@neslzkusfep a monotonic stack is O(n)

    • @neslzkusfep
      @neslzkusfep Před rokem

      @@mannyruiz7880 Yep I was wrong about the time complexity 2 years ago. Kevin's solution is O(n) because we are only pushing and popping each asteroid at most once. Access and search operations for a monotonic stack are O(n), but push and pop operations are O(1). The time complexity of the solution is O(n) because we are iterating through the entire array of asteroids once and then we are pushing and popping each asteroid at most once in O(1) time.
      So O(n) (array iteration) + O(1) (stack operations) = O(n).

  • @lalitborse
    @lalitborse Před 4 lety

    i would like to see the explanation for course schedule I and II from leetcode

  • @darod6098
    @darod6098 Před 4 lety +1

    Niiiiiiice problem. Didnt think in a Stack! Using it makes the problem more easy than medium. Thank you :)
    btw: do you know if it can be odne in place? seems like yes

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 4 lety +2

      Anytime and in place meaning modifying the original array?

    • @darod6098
      @darod6098 Před 4 lety

      @@KevinNaughtonJr yes! I mean, not creating the stack

  • @HornOKPlease
    @HornOKPlease Před 3 lety

    why does his drip go so hard

  • @SR-we1vl
    @SR-we1vl Před 3 lety +1

    Why these kinda solutions never come in my mind!

  • @switch2650
    @switch2650 Před 3 lety

    Good content

  • @goodwish1543
    @goodwish1543 Před 4 lety

    735. Asteroid Collision. Excellent! Thanks.

  • @qazyhn94
    @qazyhn94 Před 2 lety

    Isn't complexity is
    On^2?

  • @amontokoro9357
    @amontokoro9357 Před 4 lety +2

    Thanks for an amazing video! This might be dumb, but I still do not get why [-2,-1,1,2] returns itself. I thought it would return an empty array. In fact, [-3,-2,2,3] returns an empty array.

    • @pratikchowdhury9210
      @pratikchowdhury9210 Před 4 lety

      did you mean [-2,-1,1,2] and [3,2,-2,-3] ?

    • @amontokoro9357
      @amontokoro9357 Před 4 lety

      @@pratikchowdhury9210 Sorry, yes. Fixed

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 4 lety +2

      Not dumb! I'm assuming you mean [-2,-1,1,2] and it's because the first two (-2, and -1) are moving left (and will never collide with each other) and the other 2 (1 and 2) are moving right (and will never collide with each other). This example of the equivalent of us (representing an asteroid each) putting our backs against each other walking opposite directions i.e. we'll never collide

    • @amontokoro9357
      @amontokoro9357 Před 4 lety

      @@KevinNaughtonJr Thank you for your reply Kevin! I understand what you are saying. However, based on your explanation, is [-3,-2,2,3], asI mentioned above, supposed to return itself because there is no collide?

    • @stonecoldcold2941
      @stonecoldcold2941 Před 4 lety +1

      @@amontokoro9357 it should

  • @satyamgaba
    @satyamgaba Před 3 lety

    Seemed like a divide and conquer problem to me

  • @srinish1993
    @srinish1993 Před 4 lety

    The last elseif case of in can be merged

  • @rjose705
    @rjose705 Před 4 lety +2

    This O(n^2) implementation? I see 2 loops

    • @hacker-7214
      @hacker-7214 Před 4 lety

      just cuz u see 2 loops doesnt automatically mean n^2.

    • @sahilkalamkar5332
      @sahilkalamkar5332 Před 4 lety +4

      That's O(N) because each element is not processed N times. Each element is processed at most twice(pushing in and popping out), which results in linear time complexity.

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 4 lety +2

      Careful 2 loops doesn’t mean n^2 you have to think about what each of the loops are doing

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 4 lety

      Thanks for the explanation

  • @hrishikesh26
    @hrishikesh26 Před 2 lety

    Between line 10-11, shouldn’t it be - Math.abs(aesteroids[i]). As we are trying to compare the stack value vs absolutely value of potential collision element. So while(….&& stack.peak() < Math.abs(aesteroids[i]))
    @kevin

  • @goodwish1543
    @goodwish1543 Před 4 lety

    Watched 5 minutes. ha-ha, your design is using Stack, it's much simpler then mine. Thanks for sharing.
    I'll do it again with Stack.
    class Solution:
    def asteroidCollision(self, A: List[int]) -> List[int]:
    # stack
    s = []
    for v in A:
    if not s:
    s.append(v)
    elif s[-1] < 0:
    s.append(v)
    elif s[-1] > 0:
    if v > 0:
    s.append(v)
    else:
    while s and s[-1] > 0 and s[-1] < abs(v):
    s.pop()
    if not s or s[-1] < 0:
    s.append(v)
    elif s[-1] == abs(v):
    s.pop()
    return s

  • @chinmayswaroopsaini7890
    @chinmayswaroopsaini7890 Před 4 lety +1

    I almost solved the problem my code was a mess. Yours is way too clean.

  • @HenggaoCai
    @HenggaoCai Před 3 lety

    Asteroid*

  • @pratikchowdhury9210
    @pratikchowdhury9210 Před 4 lety

    we dont have lyft here in India XD

  • @laxatives
    @laxatives Před 4 lety +5

    Congrats we've now deleted this interview from our question bank. But keep studying!

  • @rasmith87
    @rasmith87 Před 2 lety

    Hitting submit without run? Psychopath.