Guess The Algorithm Challenge (FAANG Interview Questions)

แชร์
ฝัง

ความคิดเห็น • 75

  • @Mrcfski
    @Mrcfski 2 ปีที่แล้ว +30

    This is an incredibly useful format for learning theoretical solving. Thanks for the great vid, hope to see more in the future!

  • @adityagaur2223
    @adityagaur2223 2 ปีที่แล้ว +72

    you forgot to write top competitive programmer vs

    • @ferokuk
      @ferokuk 2 ปีที่แล้ว +5

      in this video he is not a top competitve programmer

  • @Avighna
    @Avighna ปีที่แล้ว

    ILYSM, this is so cool, especially the why this video is useful parts, and the abbreviated versions! Keep making videos man, huge fan!

  • @BillFye
    @BillFye 2 ปีที่แล้ว

    Hopefully you are enjoying growing your TH-cam channel Colin. I wish you nothing but the best! You are fueling my desire to consume, and also learn! Thanks!

  • @pervejmia8240
    @pervejmia8240 2 ปีที่แล้ว +3

    Incredible idea.. we need more videos like this.. it's really helpful to improve fast thinking knowledge.

  • @keikaku9298
    @keikaku9298 2 ปีที่แล้ว +1

    This was such an enjoyable video. It is way past midnight, and this is the last thing I would have wanted to do, but I went through all the questions. You will hit 1M in no time, exceptional quality videos. Keep it up!

  • @arno.claude
    @arno.claude 2 ปีที่แล้ว

    What an awesome video concept! Thank you, and hopefully we'll see more in the future!

  • @romangirin772
    @romangirin772 2 ปีที่แล้ว +1

    Very useful video!!!
    Cool example for this would be 'Maximum sum subarray' and 'Maximum product subarray'. I mean, these two seem to be almost identical problems, but one solved via greedy approach and the other via DP.

  • @joakimolovsson7310
    @joakimolovsson7310 2 ปีที่แล้ว +1

    Nice!
    This could be a recurring thing every so often to check up on your learning.
    Thanks! :)

  • @yoshi58003
    @yoshi58003 2 ปีที่แล้ว +1

    this content is awesome! i want you to continue this style content

  • @tobiahrex
    @tobiahrex 2 ปีที่แล้ว

    Super duper userful Colin. I starting doing something similar where I would take questions I've solved and create Anki flashcards, with the problem & techniques that I know about. My observation is that it's using divergent thinking to lay the tools you own onto a workbench and asking "if this is the right tool, how would i use it to solve the problem?" I think this workflow maps well to any discipline so why not CP?! Please make more. Thanks!!

  • @Polvora6
    @Polvora6 2 ปีที่แล้ว

    Really good stuff, I love the structure of the video and the interaction makes it easier to understand the topics

  • @birdbeakbeardneck3617
    @birdbeakbeardneck3617 2 ปีที่แล้ว +1

    10:41 i think u can use linear algebra, solution is s_n=a_n+b_n with a_n+1 = 2a_n+3b_n+1 = 2a_n+3b_n and (a_1,b_1) = (6,6), the problem then is transformed to matrix power, eigenvalues..., which will requires computation but reduces the problem from O(n) to O(1)

  • @mircopaul5259
    @mircopaul5259 ปีที่แล้ว

    Cool format, great selection of problems!

  • @f5673-t1h
    @f5673-t1h 2 ปีที่แล้ว +3

    Question 10: Just use Newton's method.
    Let y= x. Then iteratively update y as follows (y + x/y)/2. Once y stabilizes and remains between 2 integers, pick the lower one.

  • @g3nko0
    @g3nko0 ปีที่แล้ว

    Very useful video, I found out a lot about unknown before for me properties of the mentioned in the video algorithms just by pausing and digging/googling why it's true.

  • @f5673-t1h
    @f5673-t1h 2 ปีที่แล้ว +2

    Question 7 can just be done with a O(1) formula:
    floor((sqrt(8n+1)-1)/2)
    Let r be the number of complete rows. The ith row has i coins (possibly excluding the last), so the complete rows have 1+2+3+...+r coins. This equals r(r+1)/2, which is at most n.
    r^2 + r

    • @leonelchailand8479
      @leonelchailand8479 4 หลายเดือนก่อน

      sqrt(n) uses log n time complexity

  • @sushantrocks
    @sushantrocks 2 ปีที่แล้ว

    Bro, try this question. Asked in one of the Faangs
    Given an unordered array of ints. Find all quadruples (a[i], a[j], a[k], a[l]) such that i

  • @paspaspaspaspas
    @paspaspaspaspas 2 ปีที่แล้ว +12

    For anyone wondering about the formula at 7:18 it's just a combination with repetition formula. That is (k + n - 1) over n; where k is the set from where you can take the elements(a e i o u in this case, hence 5) and n is the number of elements you need.
    This formula counts the amount of unique n elements groups formed with the elements of the k size set. Since there is only one way to sort these groups it also counts all the sequences that we are looking for.
    PS I'm sorry for my broken english, but if you need some more explanation i'll try to answer. Otherwise you can look for "combination with repetition" on internet

  • @f5673-t1h
    @f5673-t1h 2 ปีที่แล้ว

    Question 9 with combinatorics and linear algebra:
    (This can probably be done by hand, I'm figuring it out while typing this out)
    There are "essentially" two types of rows: all 3 different, or the two outer ones the same (6 actual of each type). You only need to figure out how many rows can be put after each. (by "essentially", I mean up to some group action of flipping or recoloring)
    Think of it this way: It's like you have a graph of 12 nodes, each representing a valid row coloring, and 2 nodes are connected if the rows can be put atop of each other. Then, a valid coloring of the grid is just a walk in the grid, and you want the number of walks. But to get that, you just need to raise the adjacency matrix of this graph to the power of n-1 (there are n rows, but n-1 steps). Then finally multiply the result from the right by the column vector all 1's.
    However, you can make this graph smaller by identifying nodes of the same type together, giving you a smaller graph with 2 nodes (and a 2x2 adjacency matrix), but multiple edges between them and some self-loops. Make the new adjacency matrix out of this, and raise it to n-1, but multiply by the column vector [6, 6]^T (6 for each type).
    I found the matrix by hand, and it's just
    [3, 2]
    [2, 2]
    We need to diagonalize this, then raise the diagonal matrix to n-1, multiply by the conjugating matrices and then the vector.
    The eigenvalues involve sqrt(17), so to avoid floating point errors, it's best to work with a formal variable for it, create a "multiply" function, and then use binary exponentiation for a faster process.
    EDIT: You know what? No need for the last part with the formal variable stuff. Just binary exponentiate the matrix to n-1, then multiply by [6,6]^T.
    And I forgot to add: Just add the entries of the resulting vector for the final answer. Equivalently, just add the entries of the final matrix, then multiply by 6.

  • @saigirishwarrohitgeddam8429
    @saigirishwarrohitgeddam8429 2 ปีที่แล้ว

    This is soo cooollll!!!. I Like this! Please please make more of these videos.

  • @Andrew_J123
    @Andrew_J123 2 ปีที่แล้ว +2

    For q5, I agree on the combinatorics intuition but can you give a quick overview as to why it's that specific function I suppose. Also for q9, there's graph coloring sections of combinatorics and I think (don't quote me on this I'm really rusty at combinatorics) a chromatic polynomial type solution might do the trick, each cell of the rectangle would a node and you would have edges between adjacent cells I believe. Also I think it was a helpful video although I'll probably have to spend time going through the leetcode questions to better understand them.

  • @tagberli
    @tagberli 2 ปีที่แล้ว +2

    1:00 ngl you got me there xd

  • @f5673-t1h
    @f5673-t1h 2 ปีที่แล้ว +1

    Question 18: Kruskal/Prim's MST also works.
    If you have the MST, then just delete the edge that wasn't included in the MST.

  • @wesleyso0
    @wesleyso0 2 ปีที่แล้ว

    Love this video, thank you Colin!

  • @vishnuvs6121
    @vishnuvs6121 2 ปีที่แล้ว +2

    I have a doubt for Q17 16:30 , shouldn't we output the longest path to make sure that every node receives the message?

    • @karolinaa9478
      @karolinaa9478 2 ปีที่แล้ว

      We find the shortest path from start node to each of the nodes. Then, we return the longest of the shortest paths.

  • @lazyemperor5182
    @lazyemperor5182 ปีที่แล้ว

    More vids like this, do a sequel, really enjoyed it

  • @shmeepurt
    @shmeepurt 2 ปีที่แล้ว +2

    Why did you actually pause the video in the intro😭 i thought my phone broke. i love this channel

  • @axe8721
    @axe8721 2 ปีที่แล้ว +1

    Thank you much for this, Colin. Also, part two, when? ;)

  • @mollabeach
    @mollabeach 2 ปีที่แล้ว +1

    do you know of any other videos / resources like this (guess the algorithm ) out there? I find it very helpful

  • @f5673-t1h
    @f5673-t1h 2 ปีที่แล้ว

    Another way to do question 8 is to have a loop that removes leaves with no apples (and thei edges, of course).
    Once there are no more leaves with no apples, then the answer is just double the number of edges.
    Note that a node with no apple might not be leaf at the start of the loop, but after removing some others, then it may become one.

    • @sober_junkie5709
      @sober_junkie5709 2 ปีที่แล้ว

      what if the solution has to be strictly below O(n) ?

  • @joakimolovsson7310
    @joakimolovsson7310 2 ปีที่แล้ว +2

    For question 7, can't you solve it directly in O(1) like this:
    n - k(k+1)/2 = 0
    k = -1/2 + sqrt(1/4 + 2n)
    ans = math.floor(k)
    Edit: sqrt(n) is O(log(n))

  • @samcarter8828
    @samcarter8828 2 ปีที่แล้ว

    for question 7 you can use math.
    The fornula is floor(sqrt(n*2+0.25)-0.5)

  • @sunnykumarsingh7039
    @sunnykumarsingh7039 2 ปีที่แล้ว

    This is awesome !

  • @caiodavi9829
    @caiodavi9829 ปีที่แล้ว

    for Q18, couldnt you just remove one of the edges of the vertex with entrance degree = 2?

  • @Abhinavneelam
    @Abhinavneelam 2 ปีที่แล้ว

    Hey, Colin. Can you solve the recent CodeChef Starter problems? Some of them are very hard and I would like a different mind to attempt it. Thanks

  • @bruteforce2434
    @bruteforce2434 2 ปีที่แล้ว

    Hi Galen, Leetcode contest editorials when?

  • @cwagnello
    @cwagnello 2 ปีที่แล้ว

    Being able to decide the algorithm is important. One question I have is what do you do when you don't know the algorithm, aka how to solve the problem?

  • @samprasdsouza6993
    @samprasdsouza6993 2 ปีที่แล้ว

    we can use DSU on Q4 right ?? but I guess it will complicate the solution

  • @sumantkanala
    @sumantkanala ปีที่แล้ว

    For q3, we obviously have to sort it first right?

  • @michaelbatrakov6524
    @michaelbatrakov6524 2 ปีที่แล้ว

    love your vids

  • @FaustZZH
    @FaustZZH 2 ปีที่แล้ว

    what a great video thank you

  • @giraffe4375
    @giraffe4375 2 ปีที่แล้ว

    Thanks colin

  • @michaelkanellos5899
    @michaelkanellos5899 2 ปีที่แล้ว

    Linear Programming for most optimization problems!

  • @smalltowngamers9979
    @smalltowngamers9979 ปีที่แล้ว

    is is worth studing thies algorithm in deatil?

  • @anmol389
    @anmol389 2 ปีที่แล้ว

    Can you please do beginner's tutorial for soft soft mobile....please...

  • @faisalshaikh9061
    @faisalshaikh9061 2 ปีที่แล้ว

    do you think that I should worry about not getting the solution for most of the leetcode questions?

  • @sid9882
    @sid9882 2 ปีที่แล้ว +1

    God bless you

  • @caiodavi9829
    @caiodavi9829 ปีที่แล้ว

    couldnt you use dijkstras at Q14?

    • @caiodavi9829
      @caiodavi9829 ปีที่แล้ว

      the cost of an edge from V1 to V2 is max(0, V2 - dist[V1]). just run the normal algo using this function to calculate the cost. pretty much it

  • @Code_Solver
    @Code_Solver 2 ปีที่แล้ว +2

    Cfbr

  • @thisisakshatsri
    @thisisakshatsri 2 ปีที่แล้ว

    Score: 11/25

  • @keerthivasan9548
    @keerthivasan9548 2 ปีที่แล้ว

    Bro kindly do leetcode 862

  • @RohitSharma-gk9wd
    @RohitSharma-gk9wd ปีที่แล้ว

    made more such videos

  • @jesmon7951
    @jesmon7951 ปีที่แล้ว

    Yo just hit me that hard that, please, lemme go for crying. Brb.

  • @alperkaya8919
    @alperkaya8919 2 ปีที่แล้ว

    It took 3 minutes and 24 seconds to video to start...

  • @sadeepweerasinghe
    @sadeepweerasinghe 2 ปีที่แล้ว

    algorithm

  • @035asadali8
    @035asadali8 2 ปีที่แล้ว

    i am a cheater , i solve many of these problems so i know the answer before try to think

  • @MiketheCoder
    @MiketheCoder 2 ปีที่แล้ว

    Brains

  • @yajusgakhar6969
    @yajusgakhar6969 2 ปีที่แล้ว

    Answer to all questions was Brute Force. Noobs

  • @ahmadsofwan4069
    @ahmadsofwan4069 2 ปีที่แล้ว +1

    First!!!

  • @ramdevbaba3615
    @ramdevbaba3615 2 ปีที่แล้ว

    Hey Colin can you gift me your brain 🧠 please 🙏

  • @SPhyd
    @SPhyd 2 ปีที่แล้ว

    Are you boy or Girl?

  • @rohitbaisane6712
    @rohitbaisane6712 2 ปีที่แล้ว

    If you want larger audience you can start teaching ds and algo at youtube.

  • @johnwest8609
    @johnwest8609 2 ปีที่แล้ว

    Dude cut your hair no offense did you dad never like make fun of you for it