Set Mismatch - Leetcode 645 - Python

Поділитися
Вставка
  • Опубліковано 15 січ 2025

КОМЕНТАРІ • 38

  • @pastori2672
    @pastori2672 11 місяців тому +5

    for anyone confused about this like i was: math: M = (y - x**2) // 2 -> (18:00)
    code: M = (y -- x**2) // (2 * x) -> (19:00)
    he actually just forgot the x in the math explanation : x**2 + m**2 + 2mx - m**2 = y

    • @NeetCodeIO
      @NeetCodeIO  11 місяців тому +1

      Whoops, good catch!

    • @aryansinha1818
      @aryansinha1818 Місяць тому

      Thank you man it was irritating when I could not get this.

  • @mhd3v
    @mhd3v Рік тому +15

    Bruh that 15:13 caught me so offguard lmao 💀

  • @luiseduardoballoterosado694
    @luiseduardoballoterosado694 Рік тому +14

    Really clever math solution! I think it could simplify if you consider that (D^2 - M^2) / (D - M) is D + M. It becomes really symmetrical after that.

    • @amrlnic
      @amrlnic 11 місяців тому

      At what point? I don't understand how I can apply your case

    • @mert_dikmen
      @mert_dikmen 11 місяців тому

      @@amrlnic After finding D^2 - M^2 and D - M, you can divide the results to get D + M.
      (-5)/(-1) = 5, so D + M = 5. Which is somewhat easier to solve.

    • @amrlnic
      @amrlnic 11 місяців тому

      ok, thanks. I get it. But it turns out that D + M = y/x, so we add this y/x that is also annoying@@mert_dikmen

    • @luiseduardoballoterosado694
      @luiseduardoballoterosado694 11 місяців тому +1

      ​@@amrlnic In the math solution. He sets a two variable system of equations:
      D - M = A
      D^2 - M^2 = B
      So he transforms it into a single quadratic equation.
      By using (D^2 - M^2) / (D - M) = D + M, you can have the following system.
      D - M = A
      D + M = C (Where C = B/A)
      Which is a linear system, which has easy solutions
      D = (A + C)/2
      M = (C - D)/2

    • @amrlnic
      @amrlnic 11 місяців тому

      Thank you for the explanation. Everything is clear now

  • @CrabGuyy
    @CrabGuyy 11 місяців тому +8

    amazing solution, i was thinking of a math solution involving the sum of numbers from 1 to n being n * (n+1) / 2 and finding it out that way

    • @thespicycabbage
      @thespicycabbage 11 місяців тому

      Thats what I did!!
      class Solution:
      def findErrorNums(self, nums: List[int]) -> List[int]:
      hashmap = {}
      output = []
      totalSum = sum(nums)
      # finalSum = n(n+1)/2
      finalSum = (len(nums) * (len(nums)+1))//2
      for num in nums:
      hashmap[num] = hashmap.get(num, 0)+1
      if hashmap[num]== 2:
      output.append(num)
      output.append(finalSum - totalSum + num)
      break
      return output

  • @armandomendivil1117
    @armandomendivil1117 Рік тому +7

    I was waiting for bit manipulation solution :(

  • @michael._.
    @michael._. Рік тому +7

    15:13 me too

  • @m.kamalali
    @m.kamalali Рік тому +2

    Algebra solution is such a nice one, i thought you would mention the bit mask solution (for completeness).
    Thnks for the great effort like always!

  • @akhilsharma2864
    @akhilsharma2864 11 місяців тому +3

    15:23 aint no way 💀💀

  • @debayanbhunia7084
    @debayanbhunia7084 11 місяців тому

    This video was helpful. I knew about the maths solution but couldn't implement it because I was getting an overflow writing the code in that manner never occurred to me

  • @XboxHero2
    @XboxHero2 11 місяців тому +1

    Your videos are theraputic. I normally hate programming, but when you explain problems, I do not

  • @laumatthew71
    @laumatthew71 Рік тому

    This is a very interesting problem ! Thank you for your great explanation as usual !

  • @richardsimon395
    @richardsimon395 11 місяців тому +1

    I had multiple solutions but always got rejected bc of the order. Your output: [1,2], expected: [2, 1] etc. I got tilted of it apparently.

  • @yusufnzm
    @yusufnzm 11 місяців тому +1

    Your teaching is some next level shit brah.

  • @graceanglc
    @graceanglc 11 місяців тому +1

    I don't understand why in the formula for missing you mention y - x^2 divided by 2 but in the code it's y - x^2 divided by (2 *x)

    • @infinitehexagons6215
      @infinitehexagons6215 11 місяців тому

      It's a mistake in the video. D^2 = X^2 + M^2 + 2XM. In the video they missed the X in 2XM.

  • @harshithdesai9989
    @harshithdesai9989 Рік тому +1

    Absolutely love your videos !!! First comment ❤

  • @EzWorkzzStudios
    @EzWorkzzStudios 10 місяців тому

    I think a great algorithm for people to research for 1 to n problems is cyclic sort.

  • @ramboli4118
    @ramboli4118 Рік тому

    Love the pure algebra solution

  • @XEQUTE
    @XEQUTE Рік тому

    didn't get the in place solution but thx for the video!!

  • @ThePathToWisdomStartsNow
    @ThePathToWisdomStartsNow 11 місяців тому

    @neetcode can you do 733 - Flood Fill?

  • @deathbombs
    @deathbombs 11 місяців тому

    I offer a fourth: sort and compare values with prev value

    • @samsun387
      @samsun387 11 місяців тому

      sorting will make the run time complexity nlogn.

  • @rajsuriyang3427
    @rajsuriyang3427 11 місяців тому

    I created a range of numbers in a set and removed each number😂. What I could've done is just subtract it from the sum.

  • @andytran6830
    @andytran6830 Рік тому

    oh nice perfect timing

  • @satwiktatikonda764
    @satwiktatikonda764 Рік тому

    there is one more solution using XOR

  • @tirasjeffrey2002
    @tirasjeffrey2002 11 місяців тому +1

    all of you know how muvh i love D😭😭😭😭😭😭

  • @elyababakova2125
    @elyababakova2125 11 місяців тому

    I like that you didn't stop at O(n) space solution (unlike me 🙂). Also it's so cool that you can learn so much from an easy problem