Winning LeetCode Weekly Contest 174 + Explanations

preview_player
Показать описание
My first win on LeetCode! Anyways, explanations start at 14:05. If they are a bit unclear, feel free to ask questions in the comments below so that I can improve!

Bonus: I challenge everyone to solve the last problem in O(n), as opposed to the O(n^2) solutions most people had. Comment your solution in the description!

If this video was helpful, be sure to like & subscribe!
Рекомендации по теме
Комментарии
Автор

Amazing, Congratulation William! You can save more time by running multiple tests in one go. You just have to paste the i'th test after (i-1)th test in the custom test section. Give it a try and it may save you couple more mins.

rogernadal
Автор

Excellent . I was using topological sort to find longest path in DAG . Now i learnt 2nd method using simple dfs by watching your video . Thank u so much.

bharathateja
Автор

Congrats William! I wish I couldve done the third and fourth problem too. Will keep trying!

premierdota
Автор

dude this is awesome! Looking forward to this weekly~

bensonyuan
Автор

Congratulations on Winning your first LeetCode Contest, William ! Although this surprises me as I thought you had already won many. May you win many more in the future and May God Bless You.

May I ask a question for C ?

Here was my approach - We want to maximise (S1.S2) where S1 + S2 = S, the sum is invariant. Now, if the sum of S1 and S2 is invariant. The largest sum is when |S1 - S2| is as small as possible.

I tried each edge and examined the difference between S1 and S2 and took the values where |S1 - S2| is the minimum possible.

I thought taking the products directly would overflow and if we take the products mod M = 10^9 + 7, it might not be accurate.

For example 10^9 + 9 > 5 but 10^9 + 9 (Mod M) < 5 (Mod M)

Can you please explain how you avoided overflow ?

saikatify
Автор

does make_pair have more complexity than array stl?

bhaskarbhasku
Автор

Sir if you only make vedios of questions you solve only explaining ... It will be of great help. :)

codeWithBatta