No video

First Missing Positive || Intuition + Example + Explanation || Must Do for Amazon

  Рет қаралды 27,168

Code with Alisha

Code with Alisha

3 жыл бұрын

Given an unsorted integer array nums, return the smallest missing positive integer.
You must implement an algorithm that runs in O(n) time and uses constant extra space.
Example 1:
Input: nums = [1,2,0]
Output: 3
Example 2:
Input: nums = [3,4,-1,1]
Output: 2
Example 3:
Input: nums = [7,8,9,11,12]
Output: 1

Пікірлер: 96
@divyadwivedi1527
@divyadwivedi1527 Жыл бұрын
The BEST Explanation on UTube , got a new approach to learn,Thanks a lot
@bhandarkarsomesh8277
@bhandarkarsomesh8277 Жыл бұрын
such a great explanation, never going to forget the chair example !!
@learnwithayush7838
@learnwithayush7838 Жыл бұрын
I must say this is very underrated coding channel . You must Do an Q/A 😀
@piyushsingh9320
@piyushsingh9320 2 жыл бұрын
Not all superheriones wear capes, some of them make videos to help others..
@probabilitycodingisfunis1
@probabilitycodingisfunis1 2 жыл бұрын
Thank you so much Piyush!!
@andiamakaza24
@andiamakaza24 2 жыл бұрын
yeh aach tha
@adityarangra9019
@adityarangra9019 Жыл бұрын
aap sach mein kaafi acha explain krte ho meine 4-5 videos dekhi so that ki koi small length ki video mein explain krde.... but at the end merko yahi par aa kr ke samjh aaya pura concept ....................... your explaination is so easy to understand..... hard question bhi easily samjh aa gya
@jethala138
@jethala138 Жыл бұрын
Sweety ran away with Guddu Bhayia, that's why she was not able to sit on her chair :) Btw great explanation thanks.
@probabilitycodingisfunis1
@probabilitycodingisfunis1 Жыл бұрын
Haha lol :)
@AmanTheMystery
@AmanTheMystery 2 жыл бұрын
thanks mam great explanation, keep doing good work it helps all
@Itachi16-U
@Itachi16-U 4 ай бұрын
I went through 2 to 3 videos in youtube. No one explained better than you. Thanks for the better explanation.
@himanshulal8345
@himanshulal8345 Жыл бұрын
Nice explanation for a tricky problem... thank you..
@dhruvsanghvi5562
@dhruvsanghvi5562 7 ай бұрын
Your explaination is really great and creative, liked a lot
@gkushwanth2277
@gkushwanth2277 4 ай бұрын
superb explanation. I saw many videos for the approach of this question,among all your explanation I easily understood.
@pranjalmodanwal7842
@pranjalmodanwal7842 4 ай бұрын
best expanation on youtube. Thanks a lot!!!
@davidmwangi4312
@davidmwangi4312 Жыл бұрын
Great Explanation,
@trinitykhuman
@trinitykhuman Жыл бұрын
Great explanation. Thanks
@karandeepsingh6201
@karandeepsingh6201 Жыл бұрын
Wonderful explanation
@kameshwarmehta8435
@kameshwarmehta8435 10 ай бұрын
u have explain different approach for these question,thanku mam🙌.but u have missed one edge condition for swapping,that ele >0 && ele
@mohit7717
@mohit7717 5 ай бұрын
I like the Mother and childs example.... Nice explanation
@harshavardhanpatekar5697
@harshavardhanpatekar5697 5 ай бұрын
Great explaination!!
@akhilkhandelwal3927
@akhilkhandelwal3927 10 ай бұрын
Great Explanation di 😄. Completely Understood.
@shadabahmadkhan4986
@shadabahmadkhan4986 7 ай бұрын
Thank you ! very well explained
@deep14054
@deep14054 Жыл бұрын
Hi ma'am thanks for the solution, I came up with this solution: int firstMissingPositive(vector& nums) { int ans = 1; sort(nums.begin(), nums.end()); for(auto i: nums) if(i == ans) ans++; return ans; }
@isdardedilkisifarish3366
@isdardedilkisifarish3366 Жыл бұрын
nlogn hai ye solution
@sajalsrivastava4655
@sajalsrivastava4655 Жыл бұрын
luv u ......ek no explanation
@cringeworld8708
@cringeworld8708 Жыл бұрын
Osm solution🤜
@sahirmuzaffar883
@sahirmuzaffar883 Жыл бұрын
best explanation
@BACSShaileshShettar
@BACSShaileshShettar 7 ай бұрын
great explanation!
@JehadiHellTransportAgency
@JehadiHellTransportAgency Жыл бұрын
great work sis
@vakhariyajay315
@vakhariyajay315 Жыл бұрын
Thank you very much.
@karthikp6473
@karthikp6473 6 ай бұрын
By far the easiest approach ever
@nikhilsatyam4815
@nikhilsatyam4815 Жыл бұрын
again you explained it very well. di i have a question, i solved the question but i forget the solution after some days waht to do in this conditions.
@ASR-mz3cc
@ASR-mz3cc 7 ай бұрын
mam plz can u make videos on trees data structure, after three months we have placement interviews in college .in fact good explanation with understanding examples :)
@spritual_things05
@spritual_things05 8 күн бұрын
Thank you so much sister
@AyushSingh-nu3gt
@AyushSingh-nu3gt Жыл бұрын
too good !
@venkateswaraswamyallumolu191
@venkateswaraswamyallumolu191 5 ай бұрын
What is the difference between keeping the line “int chair = element -1 “ inside the condition and outside the condition
@Idukhan-jj9kc
@Idukhan-jj9kc 3 жыл бұрын
Perfect
@vyankateshzawar7999
@vyankateshzawar7999 Жыл бұрын
best ❤
@ugempireninjaaaaaahatori6755
@ugempireninjaaaaaahatori6755 4 ай бұрын
amazing solution , you just made mom play...
@sahilverma03
@sahilverma03 6 ай бұрын
i think in the same way we do sorting in constant space, if numbers are positive
@anvy_9924
@anvy_9924 3 ай бұрын
Hi, you explained pretty well, but the code is failing for this unit case. Input nums = [3, 4, 1, 1]. output = 1 expected = 2
@abhaydeepsharma5027
@abhaydeepsharma5027 Жыл бұрын
If anyone suffers that it is showing error , try to add condition for out of bound indexes for(int i=0;i0 && arr[i]0 && arr[i]
@ipranavprashant
@ipranavprashant Жыл бұрын
Ahh gotcha, the similar approach you used to count the minimum no of swaps to sort the array..thnx
@lavanyakataria101
@lavanyakataria101 Жыл бұрын
Grt example di, never going to forget
@lavanyakataria101
@lavanyakataria101 Жыл бұрын
& Dii you are beautiful ☺
@musharrafhussain130
@musharrafhussain130 Жыл бұрын
@@lavanyakataria101 us
@sukiratsingh985
@sukiratsingh985 6 ай бұрын
How can you say that missing no is in range [ 1,n] because in this case [7,8,9,10,11,12] all the elements are >n=6
@Rajesh-sr9us
@Rajesh-sr9us 2 жыл бұрын
After seeing this i think you are underrated
@AmanTheMystery
@AmanTheMystery 2 жыл бұрын
no she is not under rated
@lakshay6043
@lakshay6043 2 жыл бұрын
i did this question before but forgot the logic. hope the story helps.
@341yes
@341yes Жыл бұрын
Thanku!❤
@muditkhanna8164
@muditkhanna8164 11 ай бұрын
technically the TC will be > than 0(n), athough great solution.
@shvmsh20
@shvmsh20 Жыл бұрын
This story is the usp for the solution
@princepal9886
@princepal9886 Жыл бұрын
Thanks
@sansai9329
@sansai9329 2 жыл бұрын
what if the first missing element range is from 0 - n? Taking chair = element instead of element -1 should work right?
@tauffiqshaikh7419
@tauffiqshaikh7419 2 жыл бұрын
Yes, it does. Also, you must take care of element's range
@CricketGalaxy07-18
@CricketGalaxy07-18 Жыл бұрын
thanks
@reshmamaam1451
@reshmamaam1451 3 жыл бұрын
💯💯💯💯💯
@ShubhamKumarSingh6224
@ShubhamKumarSingh6224 Жыл бұрын
i thought girls are not good in coding but you proove me wrong and i'm happy to see my self being wrong
@aizad786iqbal
@aizad786iqbal 4 ай бұрын
also , one suggestion, please add code links..
@ashwinirathi238
@ashwinirathi238 Жыл бұрын
this approach is not optimal to handle this case [3,4,-1,1] to make this we need to tweak your code like this i think this sol is not optimal, i did some modification you can check n = len(nums) j=n while j: right_palace =True for i in range(n): element=nums[i] if element>=1 and element
@lonen3rd
@lonen3rd 11 ай бұрын
Works, but is the time complexity still O(n)?
@connecttorohit
@connecttorohit Жыл бұрын
@aakashgupta7211
@aakashgupta7211 2 жыл бұрын
Very secular mother😄 @5:00
@probabilitycodingisfunis1
@probabilitycodingisfunis1 Жыл бұрын
Lol , had to mix up mine, brother's and few random names :)
@AmanTheMystery
@AmanTheMystery Жыл бұрын
Thanks alisha
@sn8974
@sn8974 Жыл бұрын
Haaa bhosdiwala kitini bar message karega😂🤣
@GauravKumar-py5br
@GauravKumar-py5br Жыл бұрын
ma'am first test missing number should be 0 not 6
@roshansadhasanker3525
@roshansadhasanker3525 Жыл бұрын
why did you asssing chair value after if ?? why not before ?
@aviralarpan7350
@aviralarpan7350 Жыл бұрын
Lol
@satyams8974
@satyams8974 Жыл бұрын
Because if chair value >=nums.siz() , then in the if condition we will check for nums[char] which is invalid index. So with if condition we only give those values to chair which are lesser than size
@GAURAV-ct9pl
@GAURAV-ct9pl Жыл бұрын
thank you
@GAURAV-ct9pl
@GAURAV-ct9pl Жыл бұрын
mam, can you please tell me why can't we use swap(element,nums[chair]) instead of swap(nums[i],nums[chair])
@sunnyseconds
@sunnyseconds Жыл бұрын
nums=[3,4,-1,1] def funcpos(nums): n = len(nums) i=0 for i in range(n): element=nums[i] if element>=1 and element
@ashwinirathi238
@ashwinirathi238 Жыл бұрын
your code is not working because i=1-1 not impacted to original loop i variable i think this sol is not optimal, i did some modification you can check n = len(nums) j=n while j: right_palace =True for i in range(n): element=nums[i] if element>=1 and element
@rabindrapatra7151
@rabindrapatra7151 Ай бұрын
Alisha has a brother named as Arman
@aizad786iqbal
@aizad786iqbal 4 ай бұрын
I didn't understood the i-- part.. you were going to explain with an example then you stopped..
@codingmaster7735
@codingmaster7735 3 ай бұрын
i love you
@abhijeetrishi6472
@abhijeetrishi6472 Жыл бұрын
i think this code will fail for array with repeating elements like [3,3,3,3]
@kapilkumarsangwan6119
@kapilkumarsangwan6119 Жыл бұрын
no it will not , firstly have a look on the if condition of the code
@ferozqureshi5228
@ferozqureshi5228 Жыл бұрын
it’ll simply return 1.
@rohit-ld6fc
@rohit-ld6fc Жыл бұрын
does not work for [3,4,-1,1]
@likithareddy3025
@likithareddy3025 Жыл бұрын
yes
@ashwinirathi238
@ashwinirathi238 Жыл бұрын
@@likithareddy3025 @rohit yes this code not work for such case for that we have to made the change like and whihc makes it o(n^2) so not optimal n = len(nums) j=n while j: right_palace =True for i in range(n): element=nums[i] if element>=1 and element
@gaurav4270
@gaurav4270 Жыл бұрын
It works make sure ur decrementing i after swapping
@AmarjeetKumar-to9ub
@AmarjeetKumar-to9ub Жыл бұрын
6:25
@anurag_dutt
@anurag_dutt 8 ай бұрын
We Don't care.
@abhishekpati2006
@abhishekpati2006 Жыл бұрын
one of the most worst explanation 🤮
@akshatkaushik2037
@akshatkaushik2037 2 жыл бұрын
Line 6: Char 29: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int' (solution.cpp) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior prog_joined.cpp:15:29 help for this error
@debayanbiswas3563
@debayanbiswas3563 2 жыл бұрын
Take chair and element as long
@Vipulghadi
@Vipulghadi Жыл бұрын
@shashwatchawla
@shashwatchawla Жыл бұрын
@VivekKumar-lc3vg
@VivekKumar-lc3vg Жыл бұрын
❤️
39kgのガリガリが踊る絵文字ダンス/39kg boney emoji dance#dance #ダンス #にんげんっていいな
00:16
💀Skeleton Ninja🥷【にんげんっていいなチャンネル】
Рет қаралды 8 МЛН
Fast and Furious: New Zealand 🚗
00:29
How Ridiculous
Рет қаралды 37 МЛН
New model rc bird unboxing and testing
00:10
Ruhul Shorts
Рет қаралды 28 МЛН
Как бесплатно замутить iphone 15 pro max
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 8 МЛН
Nature's Incredible ROTATING MOTOR (It’s Electric!) - Smarter Every Day 300
29:37
Leetcode 264. Ugly Number II
18:11
Code with Alisha
Рет қаралды 12 М.
Leetcode 2401. Longest Nice Subarray | Weekly Contest 2401.
19:54
Code with Alisha
Рет қаралды 6 М.
Leetcode Decode Ways || Intuition + Code + Explanation
31:49
Code with Alisha
Рет қаралды 14 М.
Find Missing and Duplicate Number in an Array | Swap Sort Need
17:45
39kgのガリガリが踊る絵文字ダンス/39kg boney emoji dance#dance #ダンス #にんげんっていいな
00:16
💀Skeleton Ninja🥷【にんげんっていいなチャンネル】
Рет қаралды 8 МЛН