Winning LeetCode Weekly Contest 182 + Explanations

  Рет қаралды 56,030

William Lin

William Lin

Күн бұрын

1st! Explanations start at 16:10. If you have any questions, please ask them in the comments below, so that I can improve my explanations as well!
I would appreciate it if you liked this video and subscribed!
Website: williamlin.io/
Instagram: / tmwilliamlin168
Twitter: / tmwilliamlin168

Пікірлер: 177
@FisherCoder
@FisherCoder 4 жыл бұрын
00:31 Started 1st problem 01:04 Started 2nd problem 02:22 Started 3rd problem 05:36 Started 4th problem 15:20 ALL ACCEPTED! 16:10 Started explanation
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
Wait I should totally pin this, I need to figure out how
@manavdubey9581
@manavdubey9581 4 жыл бұрын
Me: reading 1st problem William: Starting 2nd problem Me: Shocked pikachu
@noenting
@noenting 4 жыл бұрын
@@tmwilliamlin168 Hey, just started learing a little. Any CP guys that use Python?
@JayPatel-jn7cu
@JayPatel-jn7cu 4 жыл бұрын
@@noenting you'll switch to c++ later
@clipit4503
@clipit4503 4 жыл бұрын
@@noenting Yeah python is very good for starting with cp switch to c++ later in when you confindent btw learning cpp is gonna be easier if you already know a language like py
@nodirhasan9843
@nodirhasan9843 4 жыл бұрын
you uploaded the video before I even finish the contest. hatts off
@rakkaalhazimi3672
@rakkaalhazimi3672 4 жыл бұрын
Lol what a speed
@kharis6770
@kharis6770 4 жыл бұрын
he: make typing sounds auto cc: [Applause]
@lerdi
@lerdi 4 жыл бұрын
When the keyboard said "clickclickclickclickclick" I really felt that..
@afeinhandler
@afeinhandler 4 жыл бұрын
Would love a video on the resources that were helpful in your CP journey. You rock.
@aleks99994
@aleks99994 4 жыл бұрын
dude you are so talented... I love your videos, wish you the best !
@MattYang
@MattYang 4 жыл бұрын
hahaha I saw you won and was wondering when this vid would come out, nice work! edit: For underground system, don't need to erase key, and don't need to initialize maps
@atypicalambience3487
@atypicalambience3487 4 жыл бұрын
I love that you just reversed the string instead of rewriting the loop.
@ShashiBhushan2k13
@ShashiBhushan2k13 4 жыл бұрын
Thanks for the great explanation William. I was stuck on last problem for couple of hours now.
@kushaalrana
@kushaalrana 4 жыл бұрын
Thanks for the explanation also bro much needed it love the way you code🔥👌
@boskomarinkovic5532
@boskomarinkovic5532 4 жыл бұрын
I know nothing about code but this seems legit
@stealth3002
@stealth3002 4 жыл бұрын
I've been coding for years and still have little to no idea what this guy is doing.
@hihello7979
@hihello7979 3 жыл бұрын
He does it so fast I can’t understand what he is doing until I pause the video lol
@JoaoVictor-lq5ew
@JoaoVictor-lq5ew 4 жыл бұрын
I love your videos man, so good
@lander2024
@lander2024 4 жыл бұрын
this guy is a legend
@enertion6923
@enertion6923 4 жыл бұрын
man i love your channel its so satisfying althought i dont understand a thing (i know another Lua so yea)
@yacinmessaoud186
@yacinmessaoud186 4 жыл бұрын
i started sweating just by watching ! simply amazing !
@stonecoldcold2941
@stonecoldcold2941 4 жыл бұрын
Hey man , really a great job in explaining. Do this always :))
@kartaLaLa
@kartaLaLa 4 жыл бұрын
Notification squad for tmw~
@atifhu
@atifhu 2 жыл бұрын
william literally code in 2x and speaks in 0.75x, what a guy
@rikohermansyah
@rikohermansyah 4 жыл бұрын
i was like "WTF is this?!!!" i graduate from informatics degree but i hate coding so freaking much, but after see this kind of bullsh*t i think i want to start learn to code sometime someday or some year maybe. you and cs dojo are freaking awesome.. i'll subscribe your channel (with the bell on) after submiting this comment.
@johnhammer8668
@johnhammer8668 4 жыл бұрын
The first problem says if there are multiple values, the largest to be returned and in the solution where is it implemented ?
@halfblood_slayer5989
@halfblood_slayer5989 4 жыл бұрын
Hey thanks man. Please do more haha. Bored in quarantine
@fatihahshamsuru1370
@fatihahshamsuru1370 4 жыл бұрын
This guy should be on a Netflix series. It's a real life hacking story.
@yinghanma1314
@yinghanma1314 4 жыл бұрын
the last question is hard af i spent a whole hour on that one and couldn't get passed
@akashgupta13
@akashgupta13 4 жыл бұрын
That's why Leetcode categorised it as *Hard* 😏
@thegodfather7994
@thegodfather7994 4 жыл бұрын
@@akashgupta13 most hard problems are doable. This one had CP vibes in it
@yinghanma1314
@yinghanma1314 4 жыл бұрын
@@thegodfather7994 exactly, even after reading some solutions i still didn't get it
@jimmorrisshen
@jimmorrisshen 4 жыл бұрын
@@akashgupta13 It is hard than usual.
@siddharthabiswas2147
@siddharthabiswas2147 4 жыл бұрын
it does'nt require any ingenuity though
@praveenchiliveri2049
@praveenchiliveri2049 4 жыл бұрын
Great Video! Learnt a lot from it .
@gamerlion472
@gamerlion472 4 жыл бұрын
He's the Flash.
@siplinayishoto
@siplinayishoto 4 жыл бұрын
Congratulations on the win! Also, what kind of keyboard do you use, because it does not sound like one of the high tech keyboards. It sounds more like an old keyboard.
@utsavsingh899
@utsavsingh899 4 жыл бұрын
Can you make a video on your gvim setup, the plugins you use and other modifications that you have made?
@fintech4220
@fintech4220 4 жыл бұрын
Yo I did this one also. My first one. I got slapped lol
@aasmohammad2651
@aasmohammad2651 Жыл бұрын
this man is faster than a computer even a computer can not solve at this speed
@ahmedouyahya
@ahmedouyahya 4 жыл бұрын
Hello William. I always wonder why almost all competitive programmers use C++. And also it will be very helpful if you make a video on how leetcode contest work. Thank you so much.
@uo5412
@uo5412 4 жыл бұрын
Awesome as always
@satyabratanaik8112
@satyabratanaik8112 4 жыл бұрын
Hey tmw, I really like your speed. Btw, which version of mingw are you using? I am using mingw-w64 but mine seems slower than yours
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
I think GCC 5.1? It might be a difference in computer speed
@shubhammanu3916
@shubhammanu3916 4 жыл бұрын
Hey William, can you please tell me that for solving a DP problem which approach should I learn? Recursive or iterative??
@TheWisp1
@TheWisp1 4 жыл бұрын
In Q3 you don't need to initialize the maps. They are just default initialized.
@user-gh8kl8ff3v
@user-gh8kl8ff3v 4 жыл бұрын
How long have you been coding and where did you learn all this magic? Very impressive!
@fridayknight1387
@fridayknight1387 4 жыл бұрын
In the first question , were we supposed to operate on sorted arrays or unsorted arrays ? Please reply ASAP .
@tonymok535
@tonymok535 4 жыл бұрын
Why youtube algorithm brings me here recently haha
@ajaib1313
@ajaib1313 4 жыл бұрын
Need to use slow motion to see his actions in beginning😍💚
@vivekgupta4051
@vivekgupta4051 4 жыл бұрын
gonna download that theme for chrome
@dkssud5630
@dkssud5630 4 жыл бұрын
What condition tilde i (~i) is in the for loop?? You used it in solve function for the last question. Thank you.
@jimmyliaouwu
@jimmyliaouwu 4 жыл бұрын
www.cplusplus.com/doc/tutorial/operators/ ~ operator is unary complement (bit inversion) ~3 is -4 (true), ~2 is -3(true), ~1 is -2(true), ~0 is -1(true), ~-1 is 0(false), ~-2 is 1(true), so for (int i = n - 1; ~i; --i) equal for (int i = n - 1; i >=0; --i) It's faster for typing.
@dkssud5630
@dkssud5630 4 жыл бұрын
@@jimmyliaouwu Thank you so much!
@wudong5422
@wudong5422 4 жыл бұрын
awesome man!!
@siddharthpanigrahi3855
@siddharthpanigrahi3855 4 жыл бұрын
hey William, did you ever do a problem like problem 4 or did idea just popped in your mind? And can you suggest some resources to study to improve my problem solving skills.
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
Yes, two very similar problems appeared in many forms 1. Count number of strings < s with digit DP 2. Count number of strings not containing a given string
@sarmaakondi485
@sarmaakondi485 4 жыл бұрын
Hi Lin, your videos are awesome. Can you recommend any books or tutorials to become competitive programmer?
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
I will
@sarmaakondi485
@sarmaakondi485 4 жыл бұрын
@@tmwilliamlin168 looking forward
@shalomalexander7811
@shalomalexander7811 2 жыл бұрын
2 Years have passed!
@jimmorrisshen
@jimmorrisshen 4 жыл бұрын
This is great and with clear explanation. Thanks a lot.
@k4i976
@k4i976 4 жыл бұрын
stay awesome!
@lawrenceliu401
@lawrenceliu401 4 жыл бұрын
How would you recommend getting from knowing the basics of programming to starting to understand competition problems? Any competition or place to start on?
@xegativ
@xegativ 4 жыл бұрын
Lawrence Liu ^
@halfblood_slayer5989
@halfblood_slayer5989 4 жыл бұрын
just jump into it XD everything in the world is practice if not talent haha edit : also subscribe and hit the bell button, maybe you'll have better luck
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
You want to start doing basic problems & learn basic algorithms. After that, it's just practice. I will make videos with more info~
@CuriousCI
@CuriousCI 4 жыл бұрын
I can't do leetcode's contests: it's 4:30 AM here in Italy when they start!
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
That's sad, at least you can do the biweeklies
@filipposcaramuzza2953
@filipposcaramuzza2953 4 жыл бұрын
Eh a chi lo dici maledizione
@supermig2287
@supermig2287 4 жыл бұрын
That's a juicy fruit for FANG, right here!
@TechnoPrefix
@TechnoPrefix 4 жыл бұрын
You are awesome
@akashgupta13
@akashgupta13 4 жыл бұрын
3rd Problem can be done in another way (probably simpler) - leetcode.com/problems/design-underground-system/discuss/554941/Java-Simple-HashMap-Solution-Clean-code Maintain 2 maps - one for checkin and one for checkout in the following way Map < Station , Map > Calculate average by iterating through checkIn map of station Add sum and count each id present in checkin[starttSation] and checkout[endStation], find average as sum / count.
@psw1
@psw1 4 жыл бұрын
Did you pass the problem with this approach? mine got TLE. Please share a link to your code if possible.
@akashgupta13
@akashgupta13 4 жыл бұрын
@@psw1 Accepted - leetcode.com/problems/design-underground-system/discuss/554941/Java-Simple-HashMap-Solution-Clean-code Submission - leetcode.com/contest/weekly-contest-182/submissions/detail/316962918/
@sadn1ck
@sadn1ck 4 жыл бұрын
how would you recommend a beginner and someone who's bad at problem solving to get started with Competitive Coding and/or DSA
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
Learn basic algos first then just keep practicing. I will make videos explaining more.
@chrischen4584
@chrischen4584 4 жыл бұрын
太神啦威廉 偶像
@jkim5118
@jkim5118 4 жыл бұрын
Man, you are amazing. What is your goal? Where do you want to go to college and where do you want to work eventually?
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
I'm going to MIT and I have no idea what I will do except that I will continue programming
@jkim5118
@jkim5118 4 жыл бұрын
@@tmwilliamlin168 Amazing! I am pretty sure you can get into any company u want. Good luck man.
@siddharthabiswas2147
@siddharthabiswas2147 4 жыл бұрын
implemented the same solution in python for Q4 gut tle fr the last case
@VivekShah98
@VivekShah98 4 жыл бұрын
I solved the last problem in the contest but what would be the approach if there were multiple evil strings in the question, and we are asked to find the number of strings lexiographically less than given string and not containing all the evil strings as substrings?
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
I think we will add more dimensions to the DP
@samueldeng2336
@samueldeng2336 4 жыл бұрын
@@tmwilliamlin168 Cool, never thought of it that way (the more complicated the problem is, the more dimensions you add). Nice work
@yunjiehong4649
@yunjiehong4649 4 жыл бұрын
why dp[n][0][1] = 1? I do not reverse e, and stuck with the base case.
@thl_leo
@thl_leo 4 жыл бұрын
Is there a reason why you put ++i instead of i++ in the for loops?
@user-he2zw2os7k
@user-he2zw2os7k 4 жыл бұрын
Very clearly
@ardisujaya
@ardisujaya 4 жыл бұрын
Could you give me advice on how to learn programming? I find it amazing when you type programs very quickly
@TBasianeyes
@TBasianeyes 4 жыл бұрын
grind leetcode
@saikalyaninduri7667
@saikalyaninduri7667 4 жыл бұрын
Can you tell an optimal solution for second question ?
@vamsia5543
@vamsia5543 4 жыл бұрын
great video Bro, could you please provide a good strategy to become a good competitive programmer just like you :) . Thanks in advance.
@DarkNix741
@DarkNix741 4 жыл бұрын
Hey William, do you have any tips on typing that quickly? What is your WPM? Im on 120 and this looks 3 times faster than I code...lol Excellent video as usual!
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
When I type normal sentences my WPM is 100-130, however, I code a lot, so that could explain the difference.
@mehulsethi5886
@mehulsethi5886 4 жыл бұрын
which IDE do you use for coding c++..i have not been able to find a good one lately..Help Me ..
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
I use GVim, but it has a steep learning curve
@realgeniusxxhackerxx4473
@realgeniusxxhackerxx4473 4 жыл бұрын
Wait for the first problem how are u able to find the largest Lucky number like 1 ,2,2,3,3,3 ur code would return 1 and not 3
@davudsafarli5356
@davudsafarli5356 3 жыл бұрын
well, He don't return *and* if it meets condition inside if. He loops through all pairs inside map. I think using rbegin would be more efficient
@JewelsPVP
@JewelsPVP 4 жыл бұрын
Subbed! Are you working in the computer science field in the future?
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
Most likely
@ervinzhang6387
@ervinzhang6387 4 жыл бұрын
Awesome
@lalom8245
@lalom8245 4 жыл бұрын
Yo this guy is sick
@praneetsingh9695
@praneetsingh9695 4 жыл бұрын
How did you learnt to implement your code so fast and win all the competitions????? any guide?
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
In short, doing a lot of practice. I will post more guiding videos soon ~
@praneetsingh9695
@praneetsingh9695 4 жыл бұрын
@@tmwilliamlin168 how long it took you from 0 to hero?? from scratch?? can you upload a video telling us how much time did you spent on data structures and algorithms?
@dezhongerzhang6130
@dezhongerzhang6130 4 жыл бұрын
the last question i get passed theought dight dp method.
@jimmorrisshen
@jimmorrisshen 4 жыл бұрын
Cool. It means that you are top 76. I think you mean Digit DP. www.geeksforgeeks.org/digit-dp-introduction/
@Sulerhy
@Sulerhy 3 ай бұрын
Your fast coding made my computer restart
@CSERohitKartik
@CSERohitKartik 4 жыл бұрын
Hey William, How did you learn Ds/Algo?
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
I will teach soon
@markliu22
@markliu22 4 жыл бұрын
May I ask what keyboard you use?
@jimmorrisshen
@jimmorrisshen 4 жыл бұрын
This is great. I translated it to python and it works. Thanks a lot. BTW, I found some other people are using KMP to solve this problem. It seems KMP based are slightly faster. Could you please help us explore a little bit about the difference of using KMP and not using KMP? Thanks a lot.
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
KMP is simply faster for calculating tr[][]
@jimmorrisshen
@jimmorrisshen 4 жыл бұрын
@@tmwilliamlin168 Thanks a lot.
@adityashrivastava8733
@adityashrivastava8733 4 жыл бұрын
Can you please make the same kind of video for yesterday's atcoder beginner contest 160?
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
I didn't have time, so I posted solutions on discord.gg/AneA5wg
@adityashrivastava8733
@adityashrivastava8733 4 жыл бұрын
@@tmwilliamlin168 i accepted the invite but don't see any solutions on any of its threads. Can you please help it?
@zachleach7118
@zachleach7118 4 жыл бұрын
can you do a typeracer video
@tianweiliu2555
@tianweiliu2555 4 жыл бұрын
To learn the solution for the last problem.
@rohitdighe852
@rohitdighe852 8 ай бұрын
In question 1, it asks to return the largest luckynum if there are more than one, you didnt account for that and yet the solution was accepted. How so?
@rohitdighe852
@rohitdighe852 8 ай бұрын
Maps in c++ are sorted during creation.
@rohitdighe852
@rohitdighe852 8 ай бұрын
sorry i use python
@rui133
@rui133 4 жыл бұрын
nice
@shashanktiwari4442
@shashanktiwari4442 4 жыл бұрын
What would be the solution for problem B if N was large??
4 жыл бұрын
I think William strategy is good because he tries to write the faster answer based on the input constraints so that do not waste time on it because at the end it is a contest. For sure he knows how to make it with a better time complexity.
@jamespaz4103
@jamespaz4103 4 жыл бұрын
I thought using nested loops is a bad idea, due to time complexity. But you do a pretty good job.
@atifhu
@atifhu 2 жыл бұрын
because constrains for n was only 200
@youssefbennoursahli917
@youssefbennoursahli917 4 жыл бұрын
what is your code editor ?
@hemavardhansankati1161
@hemavardhansankati1161 4 жыл бұрын
bro what keyboard do you use?
@skipper2795
@skipper2795 4 жыл бұрын
How hard did you study for math?
@XSTEVEN722X
@XSTEVEN722X 4 жыл бұрын
Do you have any tips on how to get started with competitive programming? I have my fair share of problems but I’m no where near your level! Also any tips with learning how to type? I’m currently learning how to touch type but I’m too slow! Great explanation btw!
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
I'll make videos on starting CP soon~ Your touch typing will become better with practice.
@akashverma5756
@akashverma5756 5 ай бұрын
TIme limit on leetcode contest is bit relaxed
@shariqshaikh5715
@shariqshaikh5715 3 жыл бұрын
Please explain all the problems you have solved in your videos also
@sanchitkumawat3803
@sanchitkumawat3803 4 жыл бұрын
how to become better in solving dp questions?
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
Do a lot of practice solving dp questions
@dulanwaduge
@dulanwaduge 4 жыл бұрын
how did you start programming? did you learn from college??
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
I learned from books. I have not graduated high school yet.
@ajourney179
@ajourney179 4 жыл бұрын
What is the difference between you and gennady korotkevich.
@stoicescueric8654
@stoicescueric8654 4 жыл бұрын
What app do you use for coding?
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
GVIM
@mohamedSayed-lr4xs
@mohamedSayed-lr4xs 4 жыл бұрын
what is the type of your keyboard ?
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
It's a mechanical keyboard
@erikjanssen2940
@erikjanssen2940 4 жыл бұрын
GoOgLe Is LoOkInG fOr YoU
@Mohammedaatif90
@Mohammedaatif90 4 жыл бұрын
i need a month to understand the last problem.
@zuowang5481
@zuowang5481 4 жыл бұрын
how is 4th a interview question
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
Maybe from Google?
@yashkumar8472
@yashkumar8472 4 жыл бұрын
Told u. ..he is GOD
@nith9009
@nith9009 4 жыл бұрын
Hi man , the first question you could do it easier like this : for loop to iterate the array , if condition to compare the an incrementing variable with the current value of the array in java it would look like this : int ans = -1; int k =0; for (int i = 0 ; i
@ilies-vip8978
@ilies-vip8978 4 жыл бұрын
Can you explain it in french ?
@erichuang5971
@erichuang5971 4 жыл бұрын
How was usaco
@tmwilliamlin168
@tmwilliamlin168 4 жыл бұрын
The contest hasn't ended yet, but you will know soon :)
@erichuang5971
@erichuang5971 4 жыл бұрын
Good luck at IOI this year 😛
@pradyothcherry3426
@pradyothcherry3426 4 жыл бұрын
That Typing sound made me to close the video..!
@obsidianskin9502
@obsidianskin9502 4 жыл бұрын
what up
@halfblood_slayer5989
@halfblood_slayer5989 4 жыл бұрын
Playing battle royale games XD
LeetCode Biweekly Contest 30 (2nd)
12:50
William Lin
Рет қаралды 52 М.
Codeforces Round #629 (Div. 3) (20th)
54:20
William Lin
Рет қаралды 19 М.
He sees meat everywhere 😄🥩
00:11
AngLova
Рет қаралды 12 МЛН
Khó thế mà cũng làm được || How did the police do that? #shorts
01:00
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 50 МЛН
ОСКАР ИСПОРТИЛ ДЖОНИ ЖИЗНЬ 😢 @lenta_com
01:01
Winning LeetCode Weekly Contest 198
40:27
William Lin
Рет қаралды 110 М.
Winning LeetCode Weekly Contest 174 + Explanations
23:05
William Lin
Рет қаралды 3,4 М.
100+ Linux Things you Need to Know
12:23
Fireship
Рет қаралды 728 М.
The Greatest Chess Player You Never Heard Of
27:26
GothamChess
Рет қаралды 536 М.
Starting Competitive Programming - Steps and Mistakes
9:55
William Lin
Рет қаралды 1,4 МЛН
How I make HARD coding problems look EASY
8:04
Sahil & Sarra
Рет қаралды 100 М.
Solving Google Code Jam Qualification Round 2020 A-D
50:53
William Lin
Рет қаралды 59 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 153 М.
Codeforces Round #640 (Div. 4) (4th)
28:34
William Lin
Рет қаралды 57 М.
Google Coding Interview With A High School Student
57:24
Clément Mihailescu
Рет қаралды 4 МЛН
ВСЕ КОНЦОВКИ И СЕКРЕТЫ ПОУ! Bou's Revenge
35:51
Family Play TV
Рет қаралды 324 М.