3267. Count Almost Equal Pairs II | Weekly Leetcode 412

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 12

  • @shivamchaudhary7574
    @shivamchaudhary7574 3 місяці тому

    Great explanation

  • @dawodujohnson
    @dawodujohnson 3 місяці тому

    Perfect explanation by the way

  • @nabhirajjain6773
    @nabhirajjain6773 3 місяці тому

    very nice and clear explanation , thanks :)

  • @vamsikrishnagannamaneni912
    @vamsikrishnagannamaneni912 3 місяці тому

    Well made video

  • @chiragbaliyan734
    @chiragbaliyan734 3 місяці тому

    leetcode weekly contest 411 ques D, can you discuss please

  • @dawodujohnson
    @dawodujohnson 3 місяці тому

    Can we solve it using disjoint set?
    Really tried hard but failed at 604/630

    • @codingmohan
      @codingmohan  3 місяці тому

      What was your approach?

    • @dawodujohnson
      @dawodujohnson 3 місяці тому

      @codingmohan I did a double for loop for all possible pairs of numbers in nums as stated in the question. Then, I used a checker function (x,y) which increments my answer by 1 if it's true.
      Now, what my checker function does is to initialize a disjoint set of size 7, iterates through the numbers while comparing them at each position. If they are different and don't belong to the same parent, then I united them
      E.g (4598, 5489)
      4 and 5 is different and so I merge them
      5 and 4 is different but they already belong to the same group
      9 and 8 is different so I merge
      8 and 9 is different but they are already merged so I skip
      I know the approach is buggy but I was wondering why disjoint set won't work

    • @ujjwalagnihotri5001
      @ujjwalagnihotri5001 2 місяці тому

      @@dawodujohnson amazing idea bro , how did you incremented your ans then, perhaps if you have to unite more than twice than it is not possible else possible and hence increase ans by 1 but the main caveat is handling leading zeroes

  • @UnknownLearner-od3qn
    @UnknownLearner-od3qn 3 місяці тому

    First viewer🥰, but sir quality is upto 360p only

    • @codingmohan
      @codingmohan  3 місяці тому +1

      It takes some time for UA-cam to process video in higher formats. It should be all good now.