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!
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
I believe this takes O(N) space because of the nums=set(nums) operation, python needs space to generate that set but the extra candidate part is technically constant!
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)?
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!
You're very welcome! Thanks so much for watching!
A beauty of this solution is using -1 index which is specific and perfect for Python!
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
I believe this takes O(N) space because of the nums=set(nums) operation, python needs space to generate that set but the extra candidate part is technically constant!
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)?
how quickly did u derive the solution urself?
what the fuck? How am i supposed to come up with this in the interview bruv?
The last solution is so sneaky, its brilliant!
Agreed! Wish I could say I came up with it on my own :)
There is a bug in you last solution : if nums[i] > 0: check should be : if nums[i]%N > 0:
Nice catch!
Please do videos explaining different search algorithms
Haha I'll try someday!
If you include the question number you'd get better SEO as people copy and paste the whole question title into youtube
We scc o no
Oo