Тёмный
NeetCode
NeetCode
NeetCode
Подписаться
Current NEET and ex-Google SWE, also I love teaching!

N.E.E.T. = (Not in education, employment or training)

Preparing for coding interviews? Checkout neetcode.io
The LeetCode Fallacy
6:08
3 месяца назад
Most Common Concepts for Coding Interviews
6:08
8 месяцев назад
Leetcode 24 Hour Challenge (while learning Golang)
24:17:16
8 месяцев назад
I quit Amazon after two months
10:09
8 месяцев назад
Google's Tech Stack (6 internal tools revealed)
9:09
10 месяцев назад
My Last Day at Google
4:59
Год назад
GPT-4 is OVERHYPED
3:51
Год назад
Will AI replace programmers?
4:08
Год назад
Is FAANG dead?
6:28
Год назад
Tech Layoffs & Hiring Freezes
5:57
Год назад
Комментарии
@sidazhong2019
@sidazhong2019 8 часов назад
I just used normal quicksort method beat 90% other solutions. Or maybe using bucket sort. I will definitely avoid this 3 pointers weird edge cases ...
@adilsaju
@adilsaju 8 часов назад
this is the best!
@kchemutai3483
@kchemutai3483 8 часов назад
Best explanation ever. Thank you neetcode
@mohammodroby8346
@mohammodroby8346 8 часов назад
Brother , I am here to learn. In my perception , I think there may a problem when we use [3,2,2,3] according your code.Waiting for your reply
@mohammodroby8346
@mohammodroby8346 8 часов назад
after simulate i found 2,2,2,3 . and the value of k is 2(This part is right)
@kwanjustin
@kwanjustin 8 часов назад
The intuition for this solution is tricky but not impossible. I'm sure many had the same question as me: "Why does dp[ len(s) ] = 1 ???" Here is the order of thinking you must take to understand: 1. The problem can be broken up into subproblems - When you draw out the decision tree, repeated work becomes apparent. Really draw it out for yourself. Draw out the trees for the following strings: "2121", "121", "21", "1". From this, you can understand dp[i] = dp[i+1] + dp[i+2] 2. Consider the edge case of an empty string " ". It does not have a leading 0, so it can validly be decoded into an empty string " " (no letter representations). 3. Consider the edge case of a single character string "1". Intuitively, we know that there is only 1 way to decode it. But how does that fit within our dp[i] = dp[i+1] + dp[i+2] formula? IT DOESN'T! But in drawing the trees, our intuition tells us that the formula should work. How can we make it work for a string with len(s) = 1? We must include it in our base case. The execution would go like this: START i. dfs(0) ii. dfs(1) -> since i == len(s), we return dp[len(s)] which we have set to equal 1 iii. The if-clause containing dfs(i+2) won't be executed, because ( i + 1 < len(s) ) won't be satisfied. iv. We return the result, which only equals dfs(1) at this point, which is 1 END 4. You see, you cannot intuitively come up with dp [ len(s) ] = 1 because you must come up with it when considering this edge case in order to force our formula to work.
@ankitdubey5045
@ankitdubey5045 9 часов назад
Those who have studied relative motion can easily understand it,taking slow to rest then the fast will meet the slow that is at rest
@ombothre2350
@ombothre2350 10 часов назад
1:57 Us
@janardannn
@janardannn 10 часов назад
tf was that 😭
@findingMyself.25yearsago
@findingMyself.25yearsago 10 часов назад
Man love these shortsss! Its easy to revise the problems as part of entertainment
@eba-pachi
@eba-pachi 11 часов назад
I get it how the inorder list can be split with the mid index, but the preorder one is still a bit magic for me.
@ShortFilmVD
@ShortFilmVD 11 часов назад
Been a while since I was an interviewee, but now if someone asked me to invert a binary tree I would politely suggest that they simply invert their traversal on read, as this would have the same effect while negating the expensive, recursive memory swapping exercise. If they really wanted to see how I would do it (to demonstrate understanding of certain concepts) I'd call out their career management bumbledom and show myself out. Man's ain't got time for silly games.
@switchyard
@switchyard 12 часов назад
I’m at about 2.5 years at Amazon. Now I am jaded 😢
@AnkitaNallana
@AnkitaNallana 14 часов назад
THANK YOU FOR SORTING IT BY THE START TIMES!
@warguy6474
@warguy6474 15 часов назад
why dfs over bfs
@ew2430
@ew2430 12 часов назад
It doesn't mater, both will traverse the same islands.
@chinmayp5859
@chinmayp5859 16 часов назад
Amazing Explaination !
@Enzoerb
@Enzoerb 17 часов назад
I really need to get better at DFS
@aurumen4706
@aurumen4706 18 часов назад
Are the questions really this easy?
@Ayooluwaigandan
@Ayooluwaigandan 18 часов назад
Sounds like the tortoise and hare solution I saw on Joma techs video
@fahim0404150
@fahim0404150 18 часов назад
The explanation is very good. However the test case have changed over the past 3 year. If i run this code in (c++) I get a "runtime error: signed integer overflow" for the input of "nums = [0,10,10,10,10,10,10,10,10,10,-10,10,10,10,10,10,10,10,10,10,0]".
@Personnenenparle
@Personnenenparle 18 часов назад
Unless the points dont have to be on corners.. then you would have failed the interview
@TheAparajit
@TheAparajit 22 часа назад
This motivated me to get back into leetcode. Thanks dude.
@martinsolorzano9071
@martinsolorzano9071 День назад
So if you hadn't seen the solution to this problem, is this something you would've thought up on your own?
@Ryuhikuro
@Ryuhikuro День назад
just hope you don't have a number to encode at the end of your string, encoding an address for example like this is bound to have issue. You could use invisible characters or better combinaison of characters (like #a trigram of the software / your name / the company#). Remember that this type of problem you have to ask question to define what are the constraint and type of data, and explain why you would implement this and not something else.
@tlz124
@tlz124 День назад
I know there's a good reason but i can't think of it. Why not use the same code for problem 1 but modified for index 1 instead of index 0?
@stevennpitt
@stevennpitt День назад
Bezos is a d---
@zhuhw
@zhuhw День назад
0:15 I think it should be "hold SP500" 😂
@chinmayee95
@chinmayee95 День назад
should be 1. while cur or stack (current while condition will not work) 2. return 0 in the end
@IamAWESOME3980
@IamAWESOME3980 День назад
is it a mistake to tell interviewer to go f himself?
@jaimew4818
@jaimew4818 День назад
class Solution { public void wallsAndGates(int[][] grid) { for(int i = 0; i < grid.length; i++) { for(int j = 0; j < grid[0].length; j++) { if(grid[i][j] == 0) { traverse(grid, i, j, 0); } } } } void traverse(int[][] A, int i, int j, int n) { if(i < 0 || j < 0 || i >= A.length || j >= A[0].length || A[i][j] == -1 || n != 0 && A[i][j] <= n) { return; } A[i][j] = n++; traverse(A, i - 1, j, n); traverse(A, i, j - 1, n); traverse(A, i + 1, j, n); traverse(A, i, j + 1, n); } }
@M60studio
@M60studio День назад
close to the concept of TLV - tag, length, value
@pastori2672
@pastori2672 День назад
oh wow new style love it
@alexsherzhukov6747
@alexsherzhukov6747 День назад
Given ~head~,… Yeah thats not gonna happen lmao
@NeetCode
@NeetCode День назад
😔
@surplusvalue3271
@surplusvalue3271 День назад
this is also quite similar to bencodes
@janardannn
@janardannn День назад
it wont anymore, python uses bignum under the hood now
@davea136
@davea136 День назад
csv libs have solved this problem. But import csv will probably not be allowed by your interviewer. But maybe it will! Give it a try.
@zg1920
@zg1920 День назад
Cool story, did not expect all that. Thanks bro.
@soul_maestro
@soul_maestro День назад
if you have the coords of all fresh oranges and of all the rotten oranges, at the start, can't you just do a A* (?) pathfinder algo from each good orange to each rotten orange, get - per good oragen - the shortest of them if multiple, if you can find such path for each fresh orange, the answer is the longest 'short path to a rotten one', else the answer is -1 aka : you can just do this massively in parallel and the moment you find even just 1 good orange with no solution in the A*pathfinding to a rotten orange, you can answer -1, not caring when which other orange turns rotten or not. done with the graph of 4:45 : A-D : rows, 1-4, colums, rotten are at A1 and A4, good ones at B1,B2,B3,B4, C3,C4 and D1 listing resuls to each rotten one : in (path to rotten at A1, path to rotten at A4): BA(1,4), B2(2,3), B3(3,2), B4(4,1), C3(4,3), C4(5,2), D1(None) -> 1 with none -> insta "-1" answer if the good one in D1 wasn't there: remove the longer pathways: B1: 1, B2: 2, B3:2, B4:1, C3:3, C4:2: highest number is 3 -> 3 is the answer. the "how long does it take to get rotten as well" part takes the longstest time and can all be done parallele for all good-bad-combo's. the path will have to be horizontal or vertical over other good oranges of course, not over empty spots.
@soul_maestro
@soul_maestro День назад
to optimise even further: if for any good orange the response is 1 step, no need to test the paths to other rotten oranges 'cause none will be shorter, if there were, it would be a rotten orange from the start and not a good one.
@-SiddharthaChappidi
@-SiddharthaChappidi День назад
Hi , whats the time complexity of the solution?
@ShivangiSingh-wc3gk
@ShivangiSingh-wc3gk День назад
I was asked to do this without extra space, I like this explanation ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-EHpS2TBfWQg.html&ab_channel=VivekanandKhyade-AlgorithmEveryDay
@rampazzo1989
@rampazzo1989 День назад
How about encoding each string to base64 (that has no commas, for example) and using comma to separate, then using Split method (C#), then decoding all? That was my solution to it, and in my case looked really simple. IDK about the big O complexity though.
@dimplekhuman9147
@dimplekhuman9147 День назад
Can't we just take set of input list and reuse combination sum I solution?
@PramodchandraP
@PramodchandraP День назад
will fail for [-2,0,-1]
@asagiai4965
@asagiai4965 День назад
inverting a binary tree here is just a function that swaps elements. so the technique is just swap from outer to inner or something. You can also use index calculation if you want to use other method.
@asagiai4965
@asagiai4965 День назад
I've always thought inverting binary tree is different from what I'm thinking. But this example is just some sort of swapping. Is that what inverting a binary tree means?
@prashantbharati1867
@prashantbharati1867 День назад
this is some serious murakami shit, but like feel good
@ljubisaknezevic9040
@ljubisaknezevic9040 День назад
Can you just use a number instead of number-special character? Looks like it can be omitted and it will work the same
@JM-gg8ct
@JM-gg8ct День назад
the string "4total" would have your code try to read 64 characters when it turns it into "64total" which is why you need a character so it becomes 6#4total
@anthonybustamante5736
@anthonybustamante5736 День назад
doesn’t work for multi-digit numbers
@meirgoldenberg5638
@meirgoldenberg5638 День назад
What do you make of the follow-up question, which asks us to come up with a worse solution that the sliding window one we already came up with?
@harryconcat
@harryconcat День назад
Yo I just search for this and you made a vid about it. For those who didn't know what this algorithm called -> Hare-Tortoise algorithm And lots of video explain how it works.
@christiankirby9650
@christiankirby9650 День назад
Please make your courses al a carte
@j.r.r.tolkien8724
@j.r.r.tolkien8724 День назад
I thought there was an invertBinaryTree function in Python. That language is a joke.