Errichto Algorithms

Errichto Algorithms

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.

LCA - Lowest Common Ancestor

LCA - Lowest Common Ancestor

Пікірлер

  • @mahimapatel8706
    @mahimapatel87068 күн бұрын

    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

  • @thecheem3764
    @thecheem37648 күн бұрын

    You are the GOAT dude.

  • @savvy2022
    @savvy20229 күн бұрын

    can I solve this problem

  • @vutiendat3601
    @vutiendat360110 күн бұрын

    thank you ❤

  • @vudo1013
    @vudo101311 күн бұрын

    thank u so much❤

  • @ahbarahad3203
    @ahbarahad320311 күн бұрын

    Nahh wtf is this :sob: this will take me 5 years to master i only have 1 to get a job lmfaoooo 😭

  • @oximas-oe9vf
    @oximas-oe9vf13 күн бұрын

    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?

  • @darkknight98-v
    @darkknight98-v14 күн бұрын

    best video on lca on the internet!!

  • @abc_cba
    @abc_cba17 күн бұрын

    Miss your content. I wish you come back. Best wishes from India

  • @ayushpareek4757
    @ayushpareek475719 күн бұрын

    pronze panstwa

  • @ironman7-eg1bk
    @ironman7-eg1bk19 күн бұрын

    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.

  • @fadlialim8762
    @fadlialim876220 күн бұрын

    I think you will like i3wm

  • @thaynaemillycavalcantesant3687
    @thaynaemillycavalcantesant368721 күн бұрын

    Really good explanation. Ty!

  • @shubhamchandra9258
    @shubhamchandra925829 күн бұрын

    37:58

  • @suharshsharma6764
    @suharshsharma6764Ай бұрын

    bro this code is failing now on leetcode do somthing

  • @jamjam3448
    @jamjam3448Ай бұрын

    thanks bro. It took me some hours to digest your solution after going through it on paper

  • @elghalib2209
    @elghalib2209Ай бұрын

    still waiting for 2d prefix sums :(

  • @carbyte2673
    @carbyte2673Ай бұрын

    Thanks a lot man!

  • @phonkabuser3985
    @phonkabuser3985Ай бұрын

    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

  • @ashrafulislamshanto
    @ashrafulislamshantoАй бұрын

    your code is now giving the wrong answer.. I don't know where it could go wrong

  • @berfubuyukoz353
    @berfubuyukoz353Ай бұрын

    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!

  • @alkhawarizm780
    @alkhawarizm780Ай бұрын

    sir please made a video for setup far manager

  • @SlateCode
    @SlateCodeАй бұрын

    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\

  • @SlateCode
    @SlateCodeАй бұрын

    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)

  • @SlateCode
    @SlateCodeАй бұрын

    Here is the updated code which uses dfs to find depth and changed loop cconstructs as explained in the video

  • @FEAMA
    @FEAMAАй бұрын

    Is it really possible to use DUCT for this game, even in C++ my algorithm always take too muche time.

  • @piotr780
    @piotr780Ай бұрын

    thinking in C++ is one of worst books ever !!! it is for C fans only - with whom he fights in this book

  • @shivanshkasaudhan4130
    @shivanshkasaudhan41302 ай бұрын

    Thanks Errichto, the solution was really an out of the box solution.

  • @codedoctor3265
    @codedoctor32652 ай бұрын

    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 ```

  • @cahyapython
    @cahyapython2 ай бұрын

    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

  • @adityarai8963
    @adityarai89632 ай бұрын

    These videos are gold mines, an ultimate treasure. Loved it.

  • @thirilochan_karthi_m.s
    @thirilochan_karthi_m.s2 ай бұрын

    What happened to this guy is he still in Competitive programming

  • @user-xo1uk7uk6d
    @user-xo1uk7uk6d4 күн бұрын

    yes

  • @Omar-Farhat
    @Omar-Farhat2 ай бұрын

    nice

  • @GenericUsername00172
    @GenericUsername001722 ай бұрын

    This is him messing with computers since childhood, parents forced him through hard shooling math is essential for this type of programming

  • @ingcivil-upm
    @ingcivil-upm2 ай бұрын

    more videoss please

  • @RahulBansal14
    @RahulBansal142 ай бұрын

    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.

  • @luizeduardoreis7657
    @luizeduardoreis76572 ай бұрын

    You are an amazing teacher

  • @madelineabio9406
    @madelineabio94062 ай бұрын

    THANK YOU

  • @glad_asg
    @glad_asg2 ай бұрын

    hey, ty for this video <3

  • @cya3mdirl158
    @cya3mdirl1582 ай бұрын

    A wiesz jak zaprojektować duży system z użyciem DDD?

  • @pythonsamurai
    @pythonsamurai2 ай бұрын

    Да говори нормально, все свои

  • @hafiz031
    @hafiz0312 ай бұрын

    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.

  • @user-pv7zx6yn9u
    @user-pv7zx6yn9u2 ай бұрын

    Love this video

  • @LearnWithAnmolll
    @LearnWithAnmolll3 ай бұрын

    your article is just awesome

  • @olayinkaanifowose5099
    @olayinkaanifowose50993 ай бұрын

    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.

  • @pankajvermacr7
    @pankajvermacr73 ай бұрын

    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

  • @debjit811
    @debjit8113 ай бұрын

    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]

  • @sahilamin219
    @sahilamin2193 ай бұрын

    This video is What i have WAITED to see for YEARS . You are FIRE 🔥

  • @agustinperez8700
    @agustinperez87003 ай бұрын

    I like more the first one, for me it's the most important, just PRACTICE.

  • @LB-qr7nv
    @LB-qr7nv3 ай бұрын

    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

  • @rachitsingh2013
    @rachitsingh20133 ай бұрын

    You should explain your code with a working example

  • @aziz0x00
    @aziz0x003 ай бұрын

    Thank you so so so much <3 <3