Guess The Algorithm Challenge (FAANG Interview Questions)

Поділитися
Вставка
  • Опубліковано 28 лис 2024

КОМЕНТАРІ • 74

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

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

  • @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 роки тому +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

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

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

  • @pervejmia8240
    @pervejmia8240 2 роки тому +3

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

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

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

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

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

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

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

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

  • @arno.claude
    @arno.claude 2 роки тому

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

  • @mircopaul5259
    @mircopaul5259 Рік тому

    Cool format, great selection of problems!

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

  • @yoshi58003
    @yoshi58003 2 роки тому +1

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

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

  • @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 роки тому +1

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

  • @samcarter8828
    @samcarter8828 2 роки тому

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

  • @Polvora6
    @Polvora6 2 роки тому

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

  • @lazyemperor5182
    @lazyemperor5182 Рік тому

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

  • @axe8721
    @axe8721 2 роки тому +1

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

  • @wesleyso0
    @wesleyso0 2 роки тому

    Love this video, thank you Colin!

  • @shmeepurt
    @shmeepurt 2 роки тому +2

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

  • @tagberli
    @tagberli 2 роки тому +2

    1:00 ngl you got me there xd

  • @mollabeach
    @mollabeach 2 роки тому +1

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

  • @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 Рік тому

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

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

  • @caiodavi9829
    @caiodavi9829 Рік тому

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

  • @bruteforce2434
    @bruteforce2434 2 роки тому

    Hi Galen, Leetcode contest editorials when?

  • @sumantkanala
    @sumantkanala Рік тому

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

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

  • @samprasdsouza6993
    @samprasdsouza6993 2 роки тому

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

  • @michaelkanellos5899
    @michaelkanellos5899 2 роки тому

    Linear Programming for most optimization problems!

  • @giraffe4375
    @giraffe4375 2 роки тому

    Thanks colin

  • @sunnykumarsingh7039
    @sunnykumarsingh7039 2 роки тому

    This is awesome !

  • @anmol389
    @anmol389 2 роки тому

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

  • @smalltowngamers9979
    @smalltowngamers9979 Рік тому

    is is worth studing thies algorithm in deatil?

  • @sid9882
    @sid9882 2 роки тому +1

    God bless you

  • @FaustZZH
    @FaustZZH 2 роки тому

    what a great video thank you

  • @Code_Solver
    @Code_Solver 2 роки тому +2

    Cfbr

  • @thisisakshatsri
    @thisisakshatsri 2 роки тому

    Score: 11/25

  • @faisalshaikh9061
    @faisalshaikh9061 2 роки тому

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

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

  • @RohitSharma-gk9wd
    @RohitSharma-gk9wd Рік тому

    made more such videos

  • @keerthivasan9548
    @keerthivasan9548 2 роки тому

    Bro kindly do leetcode 862

  • @alperkaya8919
    @alperkaya8919 2 роки тому

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

  • @MiketheCoder
    @MiketheCoder 2 роки тому

    Brains

  • @jesmon7951
    @jesmon7951 Рік тому

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

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

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

  • @rohitbaisane6712
    @rohitbaisane6712 2 роки тому

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

  • @Technology-of-You
    @Technology-of-You 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