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
@@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
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
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
Whoops, good catch!
Thank you man it was irritating when I could not get this.
Bruh that 15:13 caught me so offguard lmao 💀
i laughed
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.
At what point? I don't understand how I can apply your case
@@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.
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
@@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
Thank you for the explanation. Everything is clear now
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
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
I was waiting for bit manipulation solution :(
15:13 me too
me three
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!
15:23 aint no way 💀💀
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
Your videos are theraputic. I normally hate programming, but when you explain problems, I do not
This is a very interesting problem ! Thank you for your great explanation as usual !
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.
Your teaching is some next level shit brah.
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)
It's a mistake in the video. D^2 = X^2 + M^2 + 2XM. In the video they missed the X in 2XM.
Absolutely love your videos !!! First comment ❤
I think a great algorithm for people to research for 1 to n problems is cyclic sort.
Love the pure algebra solution
didn't get the in place solution but thx for the video!!
@neetcode can you do 733 - Flood Fill?
I offer a fourth: sort and compare values with prev value
sorting will make the run time complexity nlogn.
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.
oh nice perfect timing
there is one more solution using XOR
all of you know how muvh i love D😭😭😭😭😭😭
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