Amazon Coding Interview Question - First Missing Positive (LeetCode)

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ม.ค. 2025

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

  • @keithnorm82
    @keithnorm82 4 ปีที่แล้ว +20

    What a ridiculous problem lol. Can pretty much say I would have never thought of doing it this way. Thanks for the explanation!

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      lol yea, the optimized solution is definitely an "outside of the box" approach. Thanks for watching!

  • @manishpundir9625
    @manishpundir9625 4 ปีที่แล้ว +8

    When u started with Brute Force it helped everyone to understand the concept. I have no words how to say thank you. Great work indeed. You earned one more subscriber.

  • @JakeyCroth
    @JakeyCroth 4 ปีที่แล้ว +17

    Awesome awesome solution. Thank you for it! So refreshing to see it drawn out and explained in full, as opposed to the scores of videos out there that fail to do that.

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

      Thanks man! I'm a visual learner myself so a whiteboard explanation makes the most sense haha

    • @Sumit-yn7dn
      @Sumit-yn7dn 4 ปีที่แล้ว

      @@AlgosWithMichael bro but if we don't have 1 in array then this code fails as you are swapping every negative number with 1 then this will be marked visited ????

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

      @@Sumit-yn7dn that's why he is using a variable to check if 1 is present or not during the first traversal.

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

    The best explanation ever. Thank you so much for explaining slowly with diagrams for each edge case

  • @PATRICKCHUAD
    @PATRICKCHUAD 2 ปีที่แล้ว

    thanks for hints that we are only be looking from 1-8. I have seen other video but only now I understand this concept. your explanation is very clear.

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

    You are awesome ...Basically we are making the numbers inside the array to be in between 1 and n and traversing the array again to mark each and every elements presence by changing the sign at that index which indicates that we have seen the element,Now since we need the smallest number in between 1 and n we are traversing the array again from start....You are really Awesome

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

      I appreciate it man! It's a challenging problem for sure haha, thanks for watching!

  • @faridaragab_
    @faridaragab_ 2 ปีที่แล้ว

    The Tone of your voice makes me wanna continue listening forever .. so clear ..
    Thanks for the awesome video .. ✨

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

    after seeing the video problem looks easy, great explanation on whiteboard !!

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

    Michael, I found gold again! This one

    • @javaguru7453
      @javaguru7453 3 ปีที่แล้ว

      th-cam.com/users/maksrane100 check this too

  • @HungNguyen-tp6vt
    @HungNguyen-tp6vt ปีที่แล้ว

    thank you. From start I didn't understand but after watching your video many times. I do understand what you said. It's awesome solution.

  • @SwapnilSarkar
    @SwapnilSarkar 2 ปีที่แล้ว

    Hi man! I don't know if you still read the comments of this video but still want to say that your explanation was great. I am sure that I won't ever forget the approach of this solution.
    Thank you!

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

    Hope you are better now. Thanks for the video. Great explanation.

  • @ganeshchowdhary3024
    @ganeshchowdhary3024 4 ปีที่แล้ว

    Awesome idea handling negative numbers. This should be present in the leetcode solution.

  • @hamsalekhavenkatesh3440
    @hamsalekhavenkatesh3440 3 ปีที่แล้ว

    brilliant solution. I love the way how this problem reduced to cyclic sort

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

    Great solution. I kept attempting to define some flags to create a sort of bound in which I could find the number between the upper and lower values, but this is way more straight forward and elegant. I wonder how you get to a solution like that on your own. Thanks for posting!

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

      Some of the solutions, at least to me, seem too difficult to come up with on your own. In an actual interview you would be getting hints and what not. Thanks for watching!

  • @vibhoragarwal5425
    @vibhoragarwal5425 4 ปีที่แล้ว

    Just awesome
    extremely clear explanation not less than any professional
    keep making videos
    it helps us lot
    thanks man

  • @AM-nv4ol
    @AM-nv4ol 2 ปีที่แล้ว

    you're a godsend man. amazing explanation throughout. thank you.

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

    This is such a silly problem, Wouldn't have thought of this solution. Thanks a lot for your explanation.

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

    that was the simplest solution i watched . Thank you!

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

    Thank you so much! Amazing Explanation! Subscribed man! Initially, I thought it was an easy problem lol but then I saw your video and saw it was a Hard one, felt less guilty !

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

      Haha yea its a tough problem to get down to constant space. Thanks for watching, commenting, and subscribing!

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

    Thank you so much for such an easy explanation. This just saved my day :). Keep making more such videos.

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Anytime! More videos coming every week!

    • @rohanasokan7338
      @rohanasokan7338 3 ปีที่แล้ว

      Damn! Saved your day? What really happened to your day? xD

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

    You made it look so easy. Thanks a lot.

  • @louistannudin2486
    @louistannudin2486 3 ปีที่แล้ว

    This solution was better than the leetcode solution article

  • @dips2113
    @dips2113 4 ปีที่แล้ว +4

    This was super helpful and was explained very well. Thank you!

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      I'm so glad you found it helpful, more videos to come!

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

    Man your explanation is brilliant. Awesome!!! Thanks, dude.

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

    Beautifully explained.. keep it up brother

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

    Quick question, for the brute force, why do we add it to a set and then check? Could we not just check if if i (from 0 -> n) is in the list provided? Is it because finding it in a set rather than a list is O(1) rather than O(n)?

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

      The list is not sorted, so I don't think we can check if i (from 0 -> n) is in the list on its own.

    • @raveenadsouza2095
      @raveenadsouza2095 4 ปีที่แล้ว

      @@AlgosWithMichael Oh I meant specifically for python there’s the “in” keyword to find a value in a list so doing
      for i in range(1, len(nums)+1):
      if i not in nums:
      return i

  • @dmsohel1335
    @dmsohel1335 4 ปีที่แล้ว

    this was the best solution i have ever seen

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

    About changing out-of-range numbers to 1, what if 1 is not present in the original array? In that case you'd be adding the number 1 to the array, and hence you won't get 1 as the first missing positive number.

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

      I do a check if 1 is not present before getting to the main part of the algorithm. So,
      `if (containsOne == 0) return 1`

    • @heisenberg1844
      @heisenberg1844 4 ปีที่แล้ว

      @@AlgosWithMichael Loud and clear. Thanks.

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Nice, glad it helped!

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

    great explanation Michael. you saved me a lot of time.

  • @indrianids
    @indrianids 2 ปีที่แล้ว

    Thanks, it's awesome solution!! have think about this case about 2 days haha

  • @陈瀚龙
    @陈瀚龙 4 ปีที่แล้ว +2

    Great problem, and great explanation. Thanks!

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

    Thank you this great explanation.!!!!!

  • @sanjayizardar2263
    @sanjayizardar2263 4 ปีที่แล้ว

    Great solution.. please keep posting hard problems like this

  • @AbhishekChauhan-df3vb
    @AbhishekChauhan-df3vb 4 ปีที่แล้ว +1

    oh wow! I was thinking of so many other ways! shit, I knew this topic of absolute(). Really great explanation, thought me to think how to use techniques that I already know :) thanks a lot man! great video

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Yea, it very tricky haha, thanks for watching!

  • @vincenttan6303
    @vincenttan6303 4 ปีที่แล้ว

    this is better than the provided solution in LC which I couldn't understand.

  • @capoditutticapos19
    @capoditutticapos19 3 ปีที่แล้ว

    Very clear explanation man. This question is crazy though. Ns how a person would get the 'a-ha moment' to think of these steps, especially under pressure of an interview. Maybe i can't step inside the head of a genius lol.

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

    awesome explanation, keep going!

  • @bbbo85
    @bbbo85 3 ปีที่แล้ว

    that's so clever but shouldn't negatives and elem > n just be some number greater than n? for example 8
    because if there weren't any 1s, you would've marked 1 as seen

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

    Great explanation! Very helpful. Thanks!

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

    Thank you so much. You explained it so well. Super helpful!

  • @warnercooler4488
    @warnercooler4488 3 ปีที่แล้ว

    So well explained! Thank you so much!

  • @lokeshkumarrathinavel6566
    @lokeshkumarrathinavel6566 3 ปีที่แล้ว

    good explanation. you opened my eye. thanks Man.

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

    can you tell us how does one need to think of the optimized solution? by practice? or any helpful resources that we need to study for these kind of stuff?

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

    Super awesome ,very tricky problem

  • @user-rf4vc7mt4d
    @user-rf4vc7mt4d 2 ปีที่แล้ว

    6:20 What if 1 wasn't already in the array?

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

    [2, 2, 2, 2, 2] is it going to work?

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

    That was an amazing explanation. Thanks

  • @mrinalmathur8185
    @mrinalmathur8185 4 ปีที่แล้ว

    Why are we doing index+1 to search for the number value of index? in 11:29

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Because index is 0 based, thus we must offset it. Thank you for watching!

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

    Thanks Michael for the explanation. Just one doubt, if we are making everything greater than or all negative numbers to 1.
    Now if array is 2,3,8 it gets converted to 2,3,1 and then we check indexing and it will fail and answer will be coming as 4 but it should be 1.
    Please correct me if i understood it wrong.

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

      There is a check if there is a 1 in the array before we start changing the values. So if we do NOT find a 1, then we know our answer is 1. It is an edge that we have to consider.
      16:11 is where the edge case is handled.
      Thank you for commenting and watching, I appreciate it!

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

      @@AlgosWithMichael Got it Michael. Around 13 minutes,, coding started. So paused the video and was analysing the algorithm and found it.
      Anyways, Keep up the good work. Thanks. :)

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

      Anytime!

  • @javeedbasha6088
    @javeedbasha6088 4 ปีที่แล้ว

    Great explanation. Please do more leetcode hard problems.

  • @theuser7288
    @theuser7288 4 ปีที่แล้ว

    Explained very well.

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

    How can you explain it so well each time Michael? I am so amazed and really appreciate you!! One follow up, I also did 268. Missing Number and tried to use the same logic here, but how come I just couldn't get it right? Why is that the logic applies here but doesn't apply to an easy problem ?

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Thank you so much! I believe the problems are different in the sense of what values are allowed inside of the arrays.

    • @yitingg7942
      @yitingg7942 4 ปีที่แล้ว

      @@AlgosWithMichael Yes you are absolutely right! Thank you for your reply!!

  • @nikhilbhujbal8927
    @nikhilbhujbal8927 4 ปีที่แล้ว

    Great Explanation bro .

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

    Great explanation! Immediately subscribed after watching this video. Btw are you a student or a working professional?

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

      I appreciate that! I currently work full-time as a Software Engineer.

    • @anurandutta2217
      @anurandutta2217 4 ปีที่แล้ว

      @@AlgosWithMichael Your videos are very helpful! Keep up the good work 👍
      May I know which company are you currently working for?

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      I work for a mid-sized company in LA, not a FANG or anything like that!

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

    Hi thanks your videos are very nicely explained you got a lifetime subscriber for you .. please keep the good work

  • @sergten
    @sergten 3 ปีที่แล้ว

    Nice trick. Probably applicable to other problems.

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

      Yep, this trick is definitely seen in a lot of array restricted problems.

  • @shreyaprasad600
    @shreyaprasad600 3 ปีที่แล้ว

    Where can i get the code?

  • @VishalSharma-hq5ti
    @VishalSharma-hq5ti 4 ปีที่แล้ว +1

    Amazing explanation bro.. keep it up!!

  • @UtkarshShrivastava6009
    @UtkarshShrivastava6009 4 ปีที่แล้ว

    After watching the first 10 mins, this problem became an easy one.

  • @interviewprep6827
    @interviewprep6827 3 ปีที่แล้ว

    can you post a link to the code please??

  • @deepanshuchawala216
    @deepanshuchawala216 4 ปีที่แล้ว

    Bro, Thanks a lot .
    You saved us.

  • @aishwaryavenkat3029
    @aishwaryavenkat3029 3 ปีที่แล้ว

    Similar to counting sort where we use cur value as index and modify value in that index. Is there a generic name for that technique ? How do one comes up with such technique?

    • @javaguru7453
      @javaguru7453 3 ปีที่แล้ว

      th-cam.com/users/maksrane100 check this too

  • @codingepocs2410
    @codingepocs2410 3 ปีที่แล้ว

    best explanation thank you

    • @javaguru7453
      @javaguru7453 3 ปีที่แล้ว

      th-cam.com/users/maksrane100 check this too

  • @JoffreyB
    @JoffreyB 2 ปีที่แล้ว

    so what if we get numbers like [7, 8, 9], then we replace whatever is greater than n or less than 1 is 1, we get [1, 1, 1], than we use "seen" step, we get [-1, 1, 1], solution would be first non-negative number's index + 1, i. e. = 2, which is not true, should be 1. What gives? Where did I get it wrong?

  • @madhuravp
    @madhuravp 4 ปีที่แล้ว

    Amazing explanation!

  • @ShashwataSaha
    @ShashwataSaha 3 ปีที่แล้ว

    from heapq import heapify, heappop
    class Solution:
    def firstMissingPositive(self, nums: List[int]) -> int:
    nums=set(nums)
    nums=list(nums)
    heapify(nums)
    cnt=0
    while len(nums)>0:
    temp=heappop(nums)
    if temp

    • @AlgosWithMichael
      @AlgosWithMichael  3 ปีที่แล้ว

      Yea, it is a good solution, but I would imagine in an interview they would want the more optimized approach

  • @arpit_singh10
    @arpit_singh10 4 ปีที่แล้ว

    Great explanation bro

  • @NiteshPant
    @NiteshPant 3 ปีที่แล้ว

    # Can we do this
    for i in range (1,len(l)+1):
    if i not in l:
    print(i)
    break

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

      This doesnt run in O(n). The outer loop is O(n) and the "item in list" operation is itself an O(n) operation, so this runs in O(n^2).

  • @KanagaveluSugumar
    @KanagaveluSugumar 2 ปีที่แล้ว

    will it work with [2, 3, 4] where 4 will be swapped to 1 then [2, 3, 1] and all are negative, and the result 1 will not be found? instead 4 will be found? The problem is; it is not sure 1 as an existing value or added as replacement for edge case (negative or greater than size of array)

  • @ShashwataSaha
    @ShashwataSaha 3 ปีที่แล้ว

    How am I sure there will be always 1 in my test case?

    • @AlgosWithMichael
      @AlgosWithMichael  3 ปีที่แล้ว

      There won't necessarily always be a 1 in your test case, but it is an edge case you must handle if there is

  • @jitendrasinghbisht2289
    @jitendrasinghbisht2289 3 ปีที่แล้ว

    This is awesome. Thanks Man

    • @javaguru7453
      @javaguru7453 3 ปีที่แล้ว

      th-cam.com/users/maksrane100 check this too

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

    Good solution ❤

  • @cbjueueiwyru7472
    @cbjueueiwyru7472 3 ปีที่แล้ว

    What if 1 was the missing positive number. Wouldn't switch those to 1 mask that?

    • @AlgosWithMichael
      @AlgosWithMichael  3 ปีที่แล้ว

      I do a check if the missing number is 1, it is an extra edge that is definitely a gotcha!

  • @amu281
    @amu281 3 ปีที่แล้ว

    Hi MIchael, I have a doubt if you could clear. How it will behave for [-5, -4, -3] .

    • @AlgosWithMichael
      @AlgosWithMichael  3 ปีที่แล้ว

      I believe 1 would be the returned answer

  • @dhavalkolapkar1772
    @dhavalkolapkar1772 3 ปีที่แล้ว

    Awesome explanation. I have a question, why use a set? cant we just do Array.contains() ?

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

      Set is o(1) lookup. Array.contains is o(n)

  • @Nickel80
    @Nickel80 4 ปีที่แล้ว

    Thanks for the great explanation. Is there a name for this technique?

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Not really. The solution to this problem is really unique haha. Thanks for watching!

    • @javaguru7453
      @javaguru7453 3 ปีที่แล้ว

      th-cam.com/users/maksrane100 check this too

  • @a-33-akshaymishra5
    @a-33-akshaymishra5 4 ปีที่แล้ว

    very well explained!

  • @Krebzonide
    @Krebzonide 3 ปีที่แล้ว

    How did you get 0ms?

  • @vishnuvardhan-md1ux
    @vishnuvardhan-md1ux 4 ปีที่แล้ว

    can you do a video on dice roll simulation leetcode

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

    Please post more videos :)

  • @SC2BuildOrder
    @SC2BuildOrder 4 ปีที่แล้ว

    Why do you check the absolute value in step 2? You already turn all negatives into positive 1s in step 1...?

  • @AmitSharma-wx1wj
    @AmitSharma-wx1wj 4 ปีที่แล้ว

    what happens for [0,1,2] -> 0 -1 = -1 wil come right?

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      We do an absolute value check of the index so no index out of bounds. Also, the 0 will get changed to a 1 before the negation step!

    • @AmitSharma-wx1wj
      @AmitSharma-wx1wj 4 ปีที่แล้ว

      @@AlgosWithMichael For 0, it is not set it to 1 -- in first loop. So in second loop, int index = abs(0) - 1 = -1 will give out of bounds man.. let me know if I m missing something

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

      If you go to 19:27, I fix that mistake of not doing `

    • @AmitSharma-wx1wj
      @AmitSharma-wx1wj 4 ปีที่แล้ว

      I was trying to do it of my own after watching your approach which confused me.. you are right ! Thanks for the video !

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Gotcha, well thank you commenting and watching!

  • @fadi.casual3796
    @fadi.casual3796 4 ปีที่แล้ว

    Will this still work if missing number was 1 itself?

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Yes, I had to do an extra check to see if the missing number was 1 itself at 16:10. Thanks for watching!

  • @HARSHITKUMAR-wj4ex
    @HARSHITKUMAR-wj4ex 4 ปีที่แล้ว

    very helpful. Thanks!!

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      You're welcome! Thanks so much for watching!

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

    Why I'm hearing *Intelligence beat*

  • @nidhimittal9521
    @nidhimittal9521 2 ปีที่แล้ว

    Thanks for the amazing explanation! I have one question
    if(nums[i] == 1)
    containsOne = true;
    else if(nums[i] n){
    nums[i] = 1;
    Why the second condition is inside else if? If we have 1 in an array does it mean we don't want to update number less than equal to 0 and greater than n to 1?

    • @khateebanwer7466
      @khateebanwer7466 2 ปีที่แล้ว

      He combined the first step and the initial step to deal with an edge case:-
      1) we set all values =1 that aren't needed to proceed to the second step.
      2) We also use a flag variable to see if it encounters 1 in the array in the first pass itself and if it doesn't enocunter a 1 in first pass i.e that smallest missing positive value would be equal to 1
      3) after first pass / first execution phase , we would've checked for both the edge case (i.e 1 exists in the array or not) and also converted the useless values to one to start the next phase thereby skipping one more loop that would run till nums.length for this phase if this edge case was dealt seperately.

  • @tejasghone5118
    @tejasghone5118 4 ปีที่แล้ว

    That was smart ; ) . Thank you!

  • @code7434
    @code7434 4 ปีที่แล้ว

    we can replace out of bound numbers by INT_MAX? then during second iteration if abs(nums[i]) is INT_MAX just continue?

    • @VishalSharma-hq5ti
      @VishalSharma-hq5ti 4 ปีที่แล้ว +1

      Agreed I think replacing by 1 might cause an error?
      I think we can replace out of range numbers by any number in the range(1...n+1), provided that number is present in array or else we can choose an arbitrary number(e.g. INT_MAX)

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Yea I believe you could. However, I could see an edge case where a number in your array is INT_MAX. Thanks for watching!

  • @veliea5160
    @veliea5160 3 ปีที่แล้ว

    Can you please solve leetcode 84- Largest Rectangle in Histogram. It is a hard problem and there is not good explanation on youtube

  • @shubhamrawat2245
    @shubhamrawat2245 4 ปีที่แล้ว

    Is this a standard algorithm for this type of problems?

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Not too sure honestly haha. This problem is very different from any other problem I have seen.

  • @sandeepkumawat4982
    @sandeepkumawat4982 4 ปีที่แล้ว

    best explanation ...

  • @bhavyabansal1143
    @bhavyabansal1143 2 ปีที่แล้ว

    if all numbers are negative lets say -1,-2,-3, then first missing positive is 1 not array.length + 1.. how come this solution works then?

  • @starc701
    @starc701 4 ปีที่แล้ว

    I dont understood why we cannot write step to else if condition with
    (Nums[i] n) shouldn't we eleminate zero also. Since we want range 1 to n.. Why then we are only excluding negative and greater than n.
    You did corrected that at end... I saw it..
    Updated comment.

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

      Haha yeah I messed up

    • @starc701
      @starc701 4 ปีที่แล้ว

      @@AlgosWithMichael it was very helpful bro... Keep up the excellent work.

  • @sincelife5141
    @sincelife5141 4 ปีที่แล้ว

    Great explain

  • @anshuldogra7607
    @anshuldogra7607 4 ปีที่แล้ว

    What if the array is like A[] = {28,10,18,99,70} ?? In this case your logic that the missing number will lie between 1 to n+1 doesn't hold ! Am I missing something here ??

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

      The first missing positive in the example you provided is 1. You know your missing number will always be in the range of however many elements you have. The +1 comes from an example such as this [1, 2, 3], the first missing number would be n + 1 where n = 3, 3 + 1 = 4.

    • @anshuldogra7607
      @anshuldogra7607 4 ปีที่แล้ว

      @@AlgosWithMichael I had understood the problem incorrectly. I thought it has to be the next missing positive which in this case would have been 11. Thanks for the explanation. You've got yourself a new subscriber :)

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

      Thanks so much!

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

    Awsome Dude ..best

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

    Amazing

  • @anaysarkar7
    @anaysarkar7 4 ปีที่แล้ว

    discord link?? pls

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      If you support me on patreon, you can get access to the private community discord. Check it out in the description if that is something of interest to you!

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

    Why not swapping the numbers to their correct indices instead of looping and modifying the out of bounds to 1? That way in the first loop you would the array in the correct order. In a second loop you can just start with missing=1 and increment it every time you find a number in the correct position, and just break if found a number in the wrong position and return the missing var