Your explanations are always super well structured that after hearing the first few minutes I already get the intuition for solving the entire problem. Thanks!
Please teach a ~30 min crash course on object oriented programming in python, like your other video "python for coding interviews". You are definitely the best teacher out there.
Using Sieve of Eratosthenes for building primes factors of each number. My question is as you can see I'm checking for factor in map twice, How can I modify it such that I only have to do it once other that writing a function for that? def canTraverseAllPairs(self, nums: List[int]) -> bool: m = len(nums) uf = UnionFind(m) mx = max(nums) factor = {} # f -> index of the number with factor f primes = [i for i in range(mx + 1)] for i in range(2, mx + 1): if primes[i] == i: j = i * i while j 1: while primes[n] != n: if primes[n] in factor: uf.union(i, factor[primes[n]]) else: factor[primes[n]] = i n = n // primes[n] if primes[n] in factor: uf.union(i, factor[primes[n]]) else: factor[primes[n]] = i return uf.count == 1
@ake3881 I think you have never attended a leetcode contest, because even if you think about it, its obvious, that it breaks the whole point of contest, there will be people who would just copy his solutions (it is prohibited by the rules to upload solutions before the end of contest, they even hide testcases, so people wont brute code some test cases). If you meant like uploading his thoughts and solutions right after contests, that is ok, but there are many people who already do this.
Do you do LC everyday while having a full time job? If so how do you do it? I'm so tired after work and don't wanna do anything, so I usually LC only on weekends
I just solve daily challenge everyday. Should only take half hour at most except the problem like this 😂! Not really for interview prep only but just to keep my mind active because you rarely solve difficult algo problem at work.
1 is not a prime. because by definition a prime number can't be factorized with other prime numbers. but if you consider 1 as a prime then existence of other prime numbers isn't possible.
easier : class Solution: def canTraverseAllPairs(self, nums: List[int]) -> bool: if len(nums)==1:return True nums = set(nums) if 1 in nums:return False if len(nums)==1:return True
nums = sorted(nums,reverse=True) for i in range(len(nums)-1): for j in range(i+1,len(nums)): if gcd(nums[i],nums[j])-1: nums[j]*=nums[i] break else: return False return True
he said, that he just uses paint, I guess he has some personal settings in it. Some people use photoshop, which I think is also better to use, if you know how to set it up properly.
Learn data structures. Learn algorithms. There are more than one way to solve any problem. If you know common algorithms, you can solve most leetcode problems because thats the answer they are looking for. Also remember that being bad at leetcode doesn’t mean you are bad at coding. Also, idk if itll help you, but the way i do leetcode is copy the code into my own editor and run a loop in the terminal that runs the file forever. So when i save, the new code and output are shown right away. Also use a lot of print statements. I then copy the cases from leetcode and run the function with their input and expected value.
Streak destroyer problem
self destruction problem, every moment there is a twist
The n^2 solution too works very efficiently if you exit out when a number isn't "matched" with any other number
Your explanations are always super well structured that after hearing the first few minutes I already get the intuition for solving the entire problem. Thanks!
tysm, figured out union find but was getting tle. prime explanation helped :D
7:30 I doubt you can do union find merge in constant time. It’s usually log n time even with ranking and path compression 😊
Please teach a ~30 min crash course on object oriented programming in python, like your other video "python for coding interviews". You are definitely the best teacher out there.
every video of yours deserves more than one like. Thank you for your efforts!
Using Sieve of Eratosthenes for building primes factors of each number.
My question is as you can see I'm checking for factor in map twice, How can I modify it such that I only have to do it once other that writing a function for that?
def canTraverseAllPairs(self, nums: List[int]) -> bool:
m = len(nums)
uf = UnionFind(m)
mx = max(nums)
factor = {} # f -> index of the number with factor f
primes = [i for i in range(mx + 1)]
for i in range(2, mx + 1):
if primes[i] == i:
j = i * i
while j 1:
while primes[n] != n:
if primes[n] in factor:
uf.union(i, factor[primes[n]])
else:
factor[primes[n]] = i
n = n // primes[n]
if primes[n] in factor:
uf.union(i, factor[primes[n]])
else:
factor[primes[n]] = i
return uf.count == 1
Hey, Can you also upsolve the weekly/biweekly contests it helps a lot
Thankyou. Love your efforts ❤
He should livestream the weekly contest, I think that'll be so entertaining see the thought process live
yes please
@ake3881 I think you have never attended a leetcode contest, because even if you think about it, its obvious, that it breaks the whole point of contest, there will be people who would just copy his solutions (it is prohibited by the rules to upload solutions before the end of contest, they even hide testcases, so people wont brute code some test cases). If you meant like uploading his thoughts and solutions right after contests, that is ok, but there are many people who already do this.
Keep em coming ❤
Great explanation! Thank you so very much
14:04 - Rounding is bad idea, better to rewrite it other way around - compare squares instead of square roots.
that's what he did in the code
Neato!!! Brain's hurting!🤯
4:40 Is 1 a prime factor?
rlly good explanation, ty
Do you do LC everyday while having a full time job? If so how do you do it? I'm so tired after work and don't wanna do anything, so I usually LC only on weekends
I just solve daily challenge everyday. Should only take half hour at most except the problem like this 😂!
Not really for interview prep only but just to keep my mind active because you rarely solve difficult algo problem at work.
Afaik TH-cam and working on the NeetCode website is his full time job.
where to find your advanced algorithm course for learning union find?
This man has probably saved so many daily streaks at this point. 😂
1 is not a prime. because by definition a prime number can't be factorized with other prime numbers. but if you consider 1 as a prime then existence of other prime numbers isn't possible.
RIP streak Jan 2024 - Feb 2024.
easier :
class Solution:
def canTraverseAllPairs(self, nums: List[int]) -> bool:
if len(nums)==1:return True
nums = set(nums)
if 1 in nums:return False
if len(nums)==1:return True
nums = sorted(nums,reverse=True)
for i in range(len(nums)-1):
for j in range(i+1,len(nums)):
if gcd(nums[i],nums[j])-1:
nums[j]*=nums[i]
break
else:
return False
return True
Thanks for this, I was trying hard but this helped me save my streak
Thanks.🙃
What tools do you use for making these tutorials?
he said, that he just uses paint, I guess he has some personal settings in it. Some people use photoshop, which I think is also better to use, if you know how to set it up properly.
@@belphegor32 I’m planning to create educational animation using adobe animate, was asking for a personal suggestion
tysm
140 th like done:)) less go! ur great teacher
This is all a test of morality. Will you do the right thing: sacrifice your ego or betray your own people
Noice ❤
too hard bro
I see that I'm still weak after solving 467 problems that I couldn't recognise and understand the problem by myself :(
you are not alone 🥲
Learn data structures. Learn algorithms. There are more than one way to solve any problem. If you know common algorithms, you can solve most leetcode problems because thats the answer they are looking for. Also remember that being bad at leetcode doesn’t mean you are bad at coding.
Also, idk if itll help you, but the way i do leetcode is copy the code into my own editor and run a loop in the terminal that runs the file forever. So when i save, the new code and output are shown right away. Also use a lot of print statements. I then copy the cases from leetcode and run the function with their input and expected value.
@@lian1238 thanks
I don't even know what is union find.
Start coding in C++ again...
To be honest it is hard for me .
You are obligated to get rich so you can give back to your people and free them from
financial slavery
I bet you'd like my algo problem... Wanna solve it for me xD?
i hate this problem
TAGGR The first FULLY decentralized social network powered by the Internet Computer.