Greatest Common Divisor Traversal - Leetcode 2709 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024

ความคิดเห็น • 53

  • @akialter
    @akialter 7 หลายเดือนก่อน +54

    Streak destroyer problem

    • @sayandey1478
      @sayandey1478 5 หลายเดือนก่อน

      self destruction problem, every moment there is a twist

  • @swanv951
    @swanv951 7 หลายเดือนก่อน +4

    The n^2 solution too works very efficiently if you exit out when a number isn't "matched" with any other number

  • @siddharth-gandhi
    @siddharth-gandhi 7 หลายเดือนก่อน +7

    tysm, figured out union find but was getting tle. prime explanation helped :D

  • @edwardj4454
    @edwardj4454 7 หลายเดือนก่อน +1

    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!

  • @jamesabasifreke
    @jamesabasifreke 7 หลายเดือนก่อน +1

    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 😊

  • @VISHALS-h8y
    @VISHALS-h8y 7 หลายเดือนก่อน

    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.

  • @amaanshaikh7292
    @amaanshaikh7292 7 หลายเดือนก่อน +5

    Hey, Can you also upsolve the weekly/biweekly contests it helps a lot
    Thankyou. Love your efforts ❤

    • @drewstake3881
      @drewstake3881 7 หลายเดือนก่อน +5

      He should livestream the weekly contest, I think that'll be so entertaining see the thought process live

    • @babai2196
      @babai2196 7 หลายเดือนก่อน

      yes please

    • @belphegor32
      @belphegor32 7 หลายเดือนก่อน +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.

  • @saminhasan87
    @saminhasan87 7 หลายเดือนก่อน

    every video of yours deserves more than one like. Thank you for your efforts!

  • @akhilchauhan9417
    @akhilchauhan9417 7 หลายเดือนก่อน

    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

  • @MP-ny3ep
    @MP-ny3ep 7 หลายเดือนก่อน

    Great explanation! Thank you so very much

  • @user-j5ja95
    @user-j5ja95 7 หลายเดือนก่อน +1

    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

    • @ShikaIE
      @ShikaIE 7 หลายเดือนก่อน

      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.

    • @1vader
      @1vader 7 หลายเดือนก่อน

      Afaik TH-cam and working on the NeetCode website is his full time job.

  • @LuisEDITS_KLK
    @LuisEDITS_KLK 7 หลายเดือนก่อน

    rlly good explanation, ty

  • @tizekodnoon8305
    @tizekodnoon8305 7 หลายเดือนก่อน +1

    Neato!!! Brain's hurting!🤯

  • @Ari-pq4db
    @Ari-pq4db 7 หลายเดือนก่อน

    Keep em coming ❤

  • @mrf92
    @mrf92 7 หลายเดือนก่อน

    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.

  • @saminhasan87
    @saminhasan87 7 หลายเดือนก่อน

    where to find your advanced algorithm course for learning union find?

  • @RuslanKovtun
    @RuslanKovtun 7 หลายเดือนก่อน +1

    14:04 - Rounding is bad idea, better to rewrite it other way around - compare squares instead of square roots.

    • @thebigpaff
      @thebigpaff 7 หลายเดือนก่อน

      that's what he did in the code

  • @mrmcpherson2722
    @mrmcpherson2722 7 หลายเดือนก่อน

    This man has probably saved so many daily streaks at this point. 😂

  • @BlunderArmour
    @BlunderArmour 7 หลายเดือนก่อน +2

    RIP streak Jan 2024 - Feb 2024.

  • @BurhanAijaz
    @BurhanAijaz 7 หลายเดือนก่อน +2

    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

    • @xtremeff5428
      @xtremeff5428 7 หลายเดือนก่อน +1

      Thanks for this, I was trying hard but this helped me save my streak

  • @varunpalsingh3822
    @varunpalsingh3822 7 หลายเดือนก่อน

    tysm

  • @micorlov4321
    @micorlov4321 7 หลายเดือนก่อน +2

    4:40 Is 1 a prime factor?

  • @mudamalajayasimhareddy9517
    @mudamalajayasimhareddy9517 7 หลายเดือนก่อน

    Thanks.🙃

  • @aidanthompson5053
    @aidanthompson5053 7 หลายเดือนก่อน

    This is all a test of morality. Will you do the right thing: sacrifice your ego or betray your own people

  • @Kaviarasu_NS
    @Kaviarasu_NS 7 หลายเดือนก่อน

    What tools do you use for making these tutorials?

    • @belphegor32
      @belphegor32 7 หลายเดือนก่อน +1

      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.

    • @Kaviarasu_NS
      @Kaviarasu_NS 7 หลายเดือนก่อน

      @@belphegor32 I’m planning to create educational animation using adobe animate, was asking for a personal suggestion

  • @DeveshSoni-u6s
    @DeveshSoni-u6s 7 หลายเดือนก่อน

    140 th like done:)) less go! ur great teacher

  • @IK-xk7ex
    @IK-xk7ex 7 หลายเดือนก่อน +1

    I see that I'm still weak after solving 467 problems that I couldn't recognise and understand the problem by myself :(

    • @hiteshwadhwani629
      @hiteshwadhwani629 7 หลายเดือนก่อน

      you are not alone 🥲

    • @lian1238
      @lian1238 7 หลายเดือนก่อน

      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.

    • @hiteshwadhwani629
      @hiteshwadhwani629 7 หลายเดือนก่อน

      @@lian1238 thanks

  • @get_out_it
    @get_out_it 7 หลายเดือนก่อน

    too hard bro

  • @rajsuriyang3427
    @rajsuriyang3427 7 หลายเดือนก่อน +2

    I don't even know what is union find.

  • @Ari-pq4db
    @Ari-pq4db 7 หลายเดือนก่อน

    Noice ❤

  • @groot3271
    @groot3271 7 หลายเดือนก่อน +2

    Start coding in C++ again...

  • @aidanthompson5053
    @aidanthompson5053 7 หลายเดือนก่อน

    You are obligated to get rich so you can give back to your people and free them from
    financial slavery

  • @cocoscacao6102
    @cocoscacao6102 7 หลายเดือนก่อน

    I bet you'd like my algo problem... Wanna solve it for me xD?

  • @arijaa.9315
    @arijaa.9315 7 หลายเดือนก่อน

    To be honest it is hard for me .

  • @rohan14040
    @rohan14040 7 หลายเดือนก่อน

    i hate this problem

  • @ethronixNativeCX
    @ethronixNativeCX 7 หลายเดือนก่อน

    TAGGR The first FULLY decentralized social network powered by the Internet Computer.