Algorithms, competitive programming, coding interviews. I make educational videos and coding live streams, always sharing my thought process.
My name is Kamil Dębowski (or Errichto) and I'm quite good at competitive programming. I'm a finalist of multiple big programming competitions like ICPC, Facebook Hacker Cup and Google Code Jam (even got 2nd place in 2018). I also organize competitions, which means inventing and preparing problems.
Пікірлер
um idk how but #include <bits/stdc++.h> using namespace std; int main() { int arr[] = {2,3,5,6,8,10,12}; int x = 4; int l,r; l= 0; r = 7 -1; while (l <=r) { int m = l + (r-l)/2; if(arr[m] >= x && l == r) return arr[m]; else if (arr[m] >= x) r = m; else l = m + 1; } } seems to be working for the problem at 8:10 .. idk how i did it maybe its not a big deal but i just wanted to share now i will see errichto's soln
You are the GOAT dude.
can I solve this problem
thank you ❤
thank u so much❤
Nahh wtf is this :sob: this will take me 5 years to master i only have 1 to get a job lmfaoooo 😭
why dont we just go through the range form a to b and up the elements instead of summing from 0 to b then from 0 to a and taking the prior minus the latter?
best video on lca on the internet!!
Miss your content. I wish you come back. Best wishes from India
pronze panstwa
i have a doubt can any one say that in the leetcode question they did not mention parent[i]<i but they gave a condition where parent[i]<n but that does not satisify the condition we are assuming in writing the code.
I think you will like i3wm
Really good explanation. Ty!
37:58
bro this code is failing now on leetcode do somthing
thanks bro. It took me some hours to digest your solution after going through it on paper
still waiting for 2d prefix sums :(
Thanks a lot man!
actually no way if u average, there are lots red who reached it in 200-500 problems and there are thousands guys who cant reach even blue
your code is now giving the wrong answer.. I don't know where it could go wrong
Watching you is almost like having a 1-1 lecture with you. It's as if you are empathetic to what the learner could think of next, and you answer in the next second (or more accurately, YOU enable the learner think the right way). I get the same experience when reading the book of Martin Kleppmann. I believe this is sth you see only from great explainers. Anyway, just wanted to share. Thanks for all the effort you put through your videos Errichto!
sir please made a video for setup far manager
This code has stopped workin bcoz new test cases have been created In question it is no where mentioned that parent[i] < i, hence for the test case 12 for the parent array [-1,2,3,0] this condn gets viotlated and hence code does not works\
class TreeAncestor: def __init__(self, n: int, parent: List[int]): def dfs_depth(v): if v == 0: return 0 if depth[v]!=0: return depth[v] depth[v] = dfs_depth(parent[v]) + 1 return depth[v] self.depth = [0]*n depth = self.depth log = 0 while (1 << log) <= n: log+= 1 self.up = [[0]*log for _ in range(n)] up = self.up self.log = log #up[v][j] is the 2**j th ancestor of node v parent[0] = 0 for v in range(n): up[v][0] = parent[v] if v != 0: dfs_depth(v) for j in range(1, log): for v in range(n): up[v][j] = up[up[v][j-1]][j-1] # if v != 0: # print(depth) # depth[v] = depth[parent[v]] + 1 def getKthAncestor(self, node: int, k: int) -> int: depth = self.depth log = self.log up = self.up # print(self.depth) if depth[node] < k: return - 1 # print(self.up) for j in range(log): if k & (1 << j): node = up[node][j] return node # Your TreeAncestor object will be instantiated and called as such: # obj = TreeAncestor(n, parent) # param_1 = obj.getKthAncestor(node,k)
Here is the updated code which uses dfs to find depth and changed loop cconstructs as explained in the video
Is it really possible to use DUCT for this game, even in C++ my algorithm always take too muche time.
thinking in C++ is one of worst books ever !!! it is for C fans only - with whom he fights in this book
Thanks Errichto, the solution was really an out of the box solution.
Clean Code ``` class Solution(object): def regionsBySlashes(self, grid): """ :type grid: List[str] :rtype: int """ n = len(grid) # Create a visited matrix for each small triangle in the 2n x 2n grid visited = [[False] * (n * 3) for _ in range(n * 3)] def dfs(x, y): if x < 0 or x >= n * 3 or y < 0 or y >= n * 3 or visited[x][y]: return visited[x][y] = True directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] for dx, dy in directions: dfs(x + dx, y + dy) # Mark the slashes in the 2n x 2n grid for i in range(n): for j in range(n): if grid[i][j] == '/': visited[i * 3][j * 3 + 2] = True visited[i * 3 + 1][j * 3 + 1] = True visited[i * 3 + 2][j * 3] = True elif grid[i][j] == '\\': visited[i * 3][j * 3] = True visited[i * 3 + 1][j * 3 + 1] = True visited[i * 3 + 2][j * 3 + 2] = True regions = 0 for i in range(n * 3): for j in range(n * 3): if not visited[i][j]: dfs(i, j) regions += 1 return regions ```
10:52 , shouldn't you check if(s[i]='0') you cant add answer to it? ex: 2019 will be 2 not 1 because 019 and 19 have the same suffix edit: lol my bad, i didnt read the problem constraint carefully
These videos are gold mines, an ultimate treasure. Loved it.
What happened to this guy is he still in Competitive programming
yes
nice
This is him messing with computers since childhood, parents forced him through hard shooling math is essential for this type of programming
more videoss please
I used to waste a lot of time while solving a problem. I will stay on the problem for 1 day that was huge waste. This is a good advice think for about 20 minutes.
You are an amazing teacher
THANK YOU
hey, ty for this video <3
A wiesz jak zaprojektować duży system z użyciem DDD?
Да говори нормально, все свои
Can taking modulo M ensure the program would have produced correct results if we didn't take the modulo? As taking modulo with M will only produce results in [0, M-1] range. So, there might be some case, where two implementations (one is correct, and another is wrong) of the same problem might give the same results when we take the modulo and can bypass the test cases.
Love this video
your article is just awesome
first time seeing this, proud of myself that i was able to come up with the alternative prefix sum algorithm within minutes. Never heard of kadane's algorithm before.
Can any one help me how can i apply binary search here ? An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black pixels are connected, i.e., there is only one black region. Pixels are connected horizontally and vertically. Given the location (x, y) of one of the black pixels, return the area of the smallest (axis-aligned) rectangle that encloses all black pixels. [ [0,1,0,1,0] [0,1,0,1,0], [1,1,0,1,0], [0,1,1,1,0] ] output = 16
The last problem "Count Coin change" can be solved in a much simpler way using 1D array: dp[0] = 1; for x in nums: for i from (1 to x): dp[ i ] += dp[ i - x ]; print dp[x]
This video is What i have WAITED to see for YEARS . You are FIRE 🔥
I like more the first one, for me it's the most important, just PRACTICE.
I thought about the fake-number-solution before. Why do we need to use -1? Just use any number not in the array, for example max(array)+1
You should explain your code with a working example
Thank you so so so much <3 <3