Guess The Algorithm Challenge (FAANG Interview Questions)

Поделиться
HTML-код
  • Опубликовано: 29 янв 2025
  • НаукаНаука

Комментарии • 75

  • @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

  • @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!

  • @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 RUclips channel Colin. I wish you nothing but the best! You are fueling my desire to consume, and also learn! Thanks!

  • @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!

  • @pervejmia8240
    @pervejmia8240 2 года назад +3

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

  • @arno.claude
    @arno.claude 2 года назад

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

  • @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.

  • @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.

  • @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)

  • @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

  • @yoshi58003
    @yoshi58003 2 года назад +1

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

  • @mircopaul5259
    @mircopaul5259 Год назад

    Cool format, great selection of problems!

  • @joakimolovsson7310
    @joakimolovsson7310 2 года назад +1

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

  • @Polvora6
    @Polvora6 2 года назад

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

  • @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!!

  • @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

  • @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 года назад

    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.

  • @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.

  • @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 года назад +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!

  • @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))

  • @shmeepurt
    @shmeepurt 2 года назад +2

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

  • @lazyemperor5182
    @lazyemperor5182 Год назад

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

  • @saigirishwarrohitgeddam8429
    @saigirishwarrohitgeddam8429 2 года назад

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

  • @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.

  • @mollabeach
    @mollabeach 2 года назад +1

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

  • @axe8721
    @axe8721 2 года назад +1

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

  • @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) ?

  • @tagberli
    @tagberli 2 года назад +2

    1:00 ngl you got me there xd

  • @samcarter8828
    @samcarter8828 2 года назад

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

  • @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

  • @sunnykumarsingh7039
    @sunnykumarsingh7039 2 года назад

    This is awesome !

  • @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?

  • @sumantkanala
    @sumantkanala Год назад

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

  • @bruteforce2434
    @bruteforce2434 2 года назад

    Hi Galen, Leetcode contest editorials when?

  • @samprasdsouza6993
    @samprasdsouza6993 2 года назад

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

  • @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...

  • @michaelkanellos5899
    @michaelkanellos5899 2 года назад

    Linear Programming for most optimization problems!

  • @giraffe4375
    @giraffe4375 2 года назад

    Thanks colin

  • @FaustZZH
    @FaustZZH 2 года назад

    what a great video thank you

  • @michaelbatrakov6524
    @michaelbatrakov6524 2 года назад

    love your vids

  • @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

  • @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

  • @thisisakshatsri
    @thisisakshatsri 2 года назад

    Score: 11/25

  • @Code_Solver
    @Code_Solver 2 года назад +2

    Cfbr

  • @keerthivasan9548
    @keerthivasan9548 2 года назад

    Bro kindly do leetcode 862

  • @RohitSharma-gk9wd
    @RohitSharma-gk9wd Год назад

    made more such videos

  • @alperkaya8919
    @alperkaya8919 2 года назад

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

  • @035asadali8
    @035asadali8 2 года назад

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

  • @jesmon7951
    @jesmon7951 Год назад

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

  • @sadeepweerasinghe
    @sadeepweerasinghe 2 года назад

    algorithm

  • @MiketheCoder
    @MiketheCoder 2 года назад

    Brains

  • @ahmadsofwan4069
    @ahmadsofwan4069 2 года назад +1

    First!!!

  • @yajusgakhar6969
    @yajusgakhar6969 2 года назад

    Answer to all questions was Brute Force. Noobs

  • @ramdevbaba3615
    @ramdevbaba3615 2 года назад

    Hey Colin can you gift me your brain 🧠 please 🙏

  • @rohitbaisane6712
    @rohitbaisane6712 2 года назад

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

  • @SPhyd
    @SPhyd 2 года назад

    Are you boy or Girl?

  • @johnwest8609
    @johnwest8609 2 года назад

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