Spiral Matrix

Sdílet
Vložit
  • čas přidán 8. 07. 2024
  • For business inquiries email partnerships@k2.codes SOCIAL
    ----------------------------------------------------------------------------------------------------------------
    Instagram: / kevinnaughtonjr
    Twitter: / kevinnaughtonjr
    Patreon: / kevinnaughtonjr
    GitHub: github.com/kdn251
    MUSIC
    ----------------------------------------------------------------------------------------------------------------
    woke up tired (playboi carti - wokeuplikethis* lofi remix) by listless
    / woke-up-tired
  • Věda a technologie

Komentáře • 75

  • @KevinNaughtonJr
    @KevinNaughtonJr  Před 4 lety +6

    spirals are FUN
    instagram: instagram.com/kevinnaughtonjr/
    twitter: twitter.com/kevinnaughtonjr

  • @randeepsiddhu
    @randeepsiddhu Před 4 lety +75

    This is how you realize the importance of meaningful variable names

  • @Srijeet040689
    @Srijeet040689 Před 3 lety +7

    Absolutely beautiful! Kudos for the explanation, and for choosing meaningful variable names :)

  • @ahasunos5914
    @ahasunos5914 Před 2 lety +1

    I had the same approach to solve the problem but struggled for 3 hours because of the variable names. Thanks Kevin.

  • @shwetagoel31
    @shwetagoel31 Před 4 lety +7

    This is one of the cleanest solutions! Many thanks!

  • @igornesterov711
    @igornesterov711 Před 3 lety

    Thanks! Great explanation! And as already mentioned deal in variable names!

  • @itsbenteller1
    @itsbenteller1 Před rokem

    Such a clean solution. Thank you!

  • @darod6098
    @darod6098 Před 4 lety +2

    Thank you for all your work man :) I'm going to have an interview for interning at Facebook this month. First missing positive of LC or more videos related to Binary Search and strategies to apply on arrays would be AWESOME. Thank you.

  • @sumitanglekar6309
    @sumitanglekar6309 Před 4 lety

    You just made it look so easy again 🙌 Kudos

  • @PallNPrash
    @PallNPrash Před 3 lety

    v nice Kevin...like the way you explain your logic, even as you are typing the solution

  • @richardzhou5906
    @richardzhou5906 Před 4 lety

    This is a clean solution, very easy to understand and implement

  • @abhishekmulay759
    @abhishekmulay759 Před 4 lety

    Amazing video. Keep up the good work.

  • @subhamagarwal476
    @subhamagarwal476 Před rokem

    watched it once and got it . Thanks kevin.

  • @dhruvseth
    @dhruvseth Před 4 lety +6

    Hello great video Kevin, can you please explain why you had the && res.size() < size check condition with every for loop, I am a little lost. Thank you!

  • @lakshaygupta6180
    @lakshaygupta6180 Před 3 lety

    Thanks Kevin!! .... nice explanation

  • @pewdiepieschair2693
    @pewdiepieschair2693 Před 2 lety

    You sir are an absolute legend

  • @leanobajio
    @leanobajio Před 4 lety +1

    lovely work, Kev!

  • @Wisekuma
    @Wisekuma Před 2 lety +2

    What is the practical application of doing this - other than for a job interview?

  • @shubamsharma5745
    @shubamsharma5745 Před 4 lety

    Thankyou sir for awesome and such beautiful explanation.

  • @OverLordOfDa3rdWorld
    @OverLordOfDa3rdWorld Před 4 lety +19

    Wow, I thought about doing it this way but was afraid to because I thought the numerous for loops inside the while loop seemed wrong but apparently not lol Thanks Kevin! Just one question, why have the same check inside the for loops when the while loop does it for you ?

    • @louistannudin2486
      @louistannudin2486 Před 3 lety +2

      The nums.size() < size check is to help with dealing with certain edge cases that makes the algo (for some odd reason) run backwards like this case:
      [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
      without the check, the output is:
      [1,2,3,4,8,12,11,10,9,5,6,7,6]
      which is incorrect

    • @chintalapativenkataramarahul
      @chintalapativenkataramarahul Před 3 lety +6

      I think we need to check the same condition for all for-loops because the ArrayList may get filled mid-way of the while loop(i.e maybe after running only left to right or after top to bottom) and in that case, we don't want the rest of the for-loops to run in that iteration.

  • @mnchester
    @mnchester Před 2 lety

    amazing explanation!

  • @PramodRj
    @PramodRj Před 2 lety

    Good JOb Kevin.

  • @sumitghewade2002
    @sumitghewade2002 Před 4 lety

    Thank you so much for breaking it down so neatly.

  • @chintalapativenkataramarahul

    Thank you!

  • @vivekkumarmaheshwari3007

    This is the best solution because the approach seems pretty obvious.

  • @mailtobasit74
    @mailtobasit74 Před 3 lety +1

    Thanks a lot

  • @sowmyasg8127
    @sowmyasg8127 Před 4 lety

    finallyyy understoodd :)) thankss a lott

  • @aswink1505
    @aswink1505 Před 4 lety +3

    love your coding videos.thanks for your help. I have a quick question. If you have 5+ years of software engineer experience, should we only expect medium or hard problems?

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 4 lety

      Thanks Aswin and honestly I think it varies regardless your level of experience...i kind of think the level of difficulty you get is up to chance...but for system design interviews I think the more experience you have the more they'll expect from you!

    • @aswink1505
      @aswink1505 Před 4 lety

      got it. thanks for the info

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 4 lety

      @@aswink1505 anytime

  • @danielzuzevich4161
    @danielzuzevich4161 Před 3 lety

    Ty

  • @all-open-source
    @all-open-source Před 3 lety

    Awesome. Seems like the easiest method you come up with.

  • @ishanrtripathi
    @ishanrtripathi Před 4 lety +4

    Hi Kevin, Can you tell me what software you use to edit the videos with the music in the beginning and the end. Is it some mobile app or some Adobe software ?

  • @lordmill4572
    @lordmill4572 Před 2 lety

    dude you are genius

  • @kamalkumar7133
    @kamalkumar7133 Před 3 lety

    whole code in a single screen. GREAT

  • @surabhipriya4333
    @surabhipriya4333 Před 4 lety +4

    got this question for my interview today.. Wish i had seen this before.

    • @mohanaravind7656
      @mohanaravind7656 Před 3 lety +1

      Did you end up getting the job? and what company gave this question?

    • @surabhipriya8386
      @surabhipriya8386 Před 3 lety

      @@mohanaravind7656 Microsoft ! No I got rejected in their final round

    • @southece
      @southece Před 2 lety

      Same with me. I got this question in interview. I was not able to solve it and got rejected. Interview had only this question.

  • @naveen.v1090
    @naveen.v1090 Před 2 lety

    thank u

  • @mohammedatique8389
    @mohammedatique8389 Před 2 lety

    thanks

  • @anirudhatalmale5575
    @anirudhatalmale5575 Před 4 lety

    awesome solution

  • @swati8539
    @swati8539 Před 4 lety +1

    hey kevin
    can u suggest coding sites apart from leetcode for entire preparation for google or Amazon or Microsoft interview.
    thanks 🙂

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 4 lety

      I personally think LeetCode is the best but you can also check out hacker rank for other questions and pramp for mock interviews! If you need help preparing or want to practice mock interviews etc I offer those services too here: www.patreon.com/KevinNaughtonJr

  • @Homelander007
    @Homelander007 Před 4 lety +6

    Thanks Kevin . can you plz upload this: 1192
    Critical Connections in a Network

  • @kevinjohn553
    @kevinjohn553 Před rokem

    duddddeeeeee, I was replaying the video SOOO many times cause i didn't understand why we wrote matrix[top][right] and not matrix[ i ][right]!! and then when i gave up and continued the video it was corrected. F in the chat

  • @SpectatorAlius
    @SpectatorAlius Před 3 lety +1

    The inotro and outro music are rather goofy, but it is *so* nice to hear an algorithm explained in normal, US accent English instead of, well, you know!

    • @KevinNaughtonJr
      @KevinNaughtonJr  Před 3 lety

      SpectatorAlius if you like my explanations check out the interviewing service I just released thedailybyte.dev/?ref=kevin

  • @vishweshthakur2234
    @vishweshthakur2234 Před 4 lety +4

    i think in second loop of for where list is added , it should be
    nums.add(matrix[i][right]) ; in place of nums.add(matrix[top][right]) , else it will repeat 6

  • @varunsadhu9060
    @varunsadhu9060 Před 4 lety +1

    Hey , i guess the 2nd for loop instead of top it should be [i]

  • @kunalkavthekar3747
    @kunalkavthekar3747 Před 4 lety

    hey Kevin,
    great work on these problems, helped me understand a lot of patterns.
    can you just link the songs that you put in your videos?
    you have a great playlist!

  • @Oscar-ig2gm
    @Oscar-ig2gm Před 3 lety

    I wrote the same solution)

  • @davidpham6330
    @davidpham6330 Před 4 lety +1

    Used to watch Indians teach on CZcams. Now I watch Kevin. I love you

  • @rohananjaria1009
    @rohananjaria1009 Před 3 lety

    You look like Ozan Kabak from Liverpool FC

  • @DaKingOfBall23
    @DaKingOfBall23 Před 3 lety +1

    this one doesnt work, but the one on your github does. this one works for 3x3 but not for 3*4

  • @abhinavghosh725
    @abhinavghosh725 Před 4 lety +2

    hey kevin!
    what kind of a moustache is that!

  • @riya6549
    @riya6549 Před 2 lety

    so my uni wants to print a matrix in a spiral form...but the matrix is a 3D lmao

    • @y.5107
      @y.5107 Před rokem

      holy shit I fail doing it in 2d

  • @kyle7382
    @kyle7382 Před 3 lety

    function createMatrix(n, m = n) {
    let i = 1;
    return new Array(m).fill(null).map(() => {
    return new Array(n).fill(null).map(() => i++)
    })
    }
    function spiralTraverseMatrix(matrix) {
    const items = [];
    if (!matrix.length) return items;
    let top = 0;
    let bottom = matrix.length - 1;
    let left = 0;
    let right = matrix[0].length - 1;
    const size = (bottom + 1) * (right + 1);
    while(
    top

  • @Simple_person221
    @Simple_person221 Před 4 lety

    Its wrong answer, even your screen says it wrong answer, just compare output and expected output

  • @bismeetsingh352
    @bismeetsingh352 Před 3 lety

    I solved recursively: leetcode.com/problems/spiral-matrix/discuss/847626/Recursive-Solution

  • @penmaniac
    @penmaniac Před 3 lety

    There are all Indians in The Comment section 😂😂😂😂

  • @kicksomeup6998
    @kicksomeup6998 Před 2 lety

    Wow, the nums.size() check was amazing.