(Old) Leetcode 41 - Arrays | First Missing Positive

preview_player
Показать описание
Topic: Arrays

Code:

Leetcode:

*Note* I claim no rights to this question. All rights belong to Leetcode. If I'm reviewing a solution that was from another Leetcode user or Leetcode itself I will give credit below.

Рекомендации по теме
Комментарии
Автор

I remade this video to explain it better

NideeshTerapalli
Автор

you should be a lot clearer on why we do something if we do so... you are in a hurry.. thanks

nareshnepal
Автор

bhai thoda aur explain krke btao, , , , kis chij ka jldi h

anshukumar
Автор

Hey Nideesh. I don't get one thing: You encounter 3, and you change the sign of arr[3] to negative. What if there already is some value at arr[3] which you needed to process?

mihirtrivedi
Автор

I think the last step where a[0]>0 return n+1; is invalid it should be a[0]>0 return we are setting a[0]=-a[0] when (a[i]==n) which means the nth number is present in the given after traversing this=> for(i=1 ; i<n ; i++) {
if(a[i]>0) return i;
}
if(a[0]>0) return n;
else return n+1;



 if I'm wrong please correct me!
btw thanks for this video (^_^)

nayanthulkar
Автор

I closed the tab at 0:17 "The answer that they want us to return is actually the index of the array which has the first non negative number after we are done processing... "

You don't even know what the output should be.

duedares
Автор

Hi Nideesh. Thanks for making the effort to share the solution. But I didn't quite find the logic or explanation of how this approach solves the problem, as in why we chose this approach. Rather than getting to a solution, I am more interested in the approach as I prepare.

VarunVermaUSC
Автор

why do we need math.abs? isnt it guaranteed that everything at that poit in the array is a positive?

irvinge