Leetcode - First Missing Positive (Python)

preview_player
Показать описание
September 2020 Leetcode Challenge
Leetcode - First Missing Positive
Рекомендации по теме
Комментарии
Автор

Watching you build upon the previous solutions is what makes the "optimal" solution much easier to be understood. There's another approach that multiplies the "seen" numbers by -1 instead of adding the modulo.
Thank you for your videos!

Автор

A beauty of this solution is using -1 index which is specific and perfect for Python!

lianghe
Автор

Thanks for the nice solution! I have a question about it. Based on the desc of the problem, nums[I] could go as high 2^32-1. So if adding those numbers with N, it would go beyond the MAX integer for many other languages such as Java. I know it is not an issue with Python, but would it still add storage (numbers from 32 bits to 64 bits), thus the memory complexity becomes o(N)?

lianghe
Автор

thanks tim! really appreciate the explanation for the O(1) space! i was wondering if a solution like this is still 0(1) space:

if not nums:
return 1
nums = [num for num in nums if num > 0]
nums = set(nums)
if not nums:
return 1

candidate = 1
while candidate <= max(nums) + 1:
if candidate not in nums:
return candidate
candidate += 1
return candidate

i mean i have to fiddle with the first allocation of nums first. but the extra candidate vars is still technically constant?

janmichaelaustria
Автор

The last solution is so sneaky, its brilliant!

samarthasthana
Автор

Please do videos explaining different search algorithms

danielshea
Автор

how quickly did u derive the solution urself?

qazaqempire
Автор

If you include the question number you'd get better SEO as people copy and paste the whole question title into youtube

oooo-rcyf
Автор

There is a bug in you last solution : if nums[i] > 0: check should be : if nums[i]%N > 0:

laofengs
Автор

what the fuck? How am i supposed to come up with this in the interview bruv?

rosefromdead
visit shbcf.ru