LeetCode Pascal's Triangle Solution Explained - Java

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ม.ค. 2019
  • The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
    Join my free exclusive community built to empower programmers! - www.skool.com/software-develo...
    Preparing For Your Coding Interviews? Use These Resources
    --------------------
    (My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.dev/courses/nick
    AlgoCademy - algocademy.com/?referral=nick...
    Daily Coding Interview Questions - bit.ly/3xw1Sqz
    10% Off Of The Best Web Hosting! - hostinger.com/nickwhite
    Follow My Twitter - / nicholaswwhite
    Follow My Instagram - / nickwwhite
    Other Social Media
    ----------------------------------------------
    Discord - / discord
    Twitch - / nickwhitettv
    TikTok - / nickwhitetiktok
    LinkedIn - / nicholas-w-white
    Show Support
    ------------------------------------------------------------------------------
    Patreon - / nick_white
    PayPal - paypal.me/nickwwhite?locale.x...
    Become A Member - / @nickwhite
    #coding #programming #softwareengineering
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @noctua7771
    @noctua7771 ปีที่แล้ว +13

    I love how you quickly go through the algorithm without getting slowed down by overly simplified explanations. Perfect pace. Love it!

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

      tru

  • @abhishekpandey3105
    @abhishekpandey3105 4 ปีที่แล้ว +50

    love and respect from India. there are thousand of teachers/professionals doing the same thing on TH-cam, but still you got something which keeps me bounded to this channel.Thank you for making such great explanatory videos.

  • @sk8tergal995
    @sk8tergal995 4 ปีที่แล้ว +3

    Great explanation!! Really loved how you explained everything to the minute details for programming beginners like me. Subbed, thanks!❤

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

    Big Respect from Ethiopia!, Nick the way you make things as simple as possible but to the very point is just superb!

  • @fangzhang7434
    @fangzhang7434 5 ปีที่แล้ว +9

    Thanks for sharing! This code is clear and well presented

  • @isssamsam8623
    @isssamsam8623 10 หลายเดือนก่อน +1

    after 4 years and you still earnings subscribers and respect , i really like you man , thanks for those helpfull videos

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

    Hey nick your algorithm videos are just great.

  • @hacker-7214
    @hacker-7214 4 ปีที่แล้ว +78

    Damn this question was lowkey hard.

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

      all are lowkey "hard"

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

      @@rodanm bro, quick question, is watching someone solve this a bit like cheating ? Or is it normal for most students of this topic to watch how it's done ?

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

      @@UnknownSend3r if you understand it , and you can write the code without copying it then its okay .

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

      @@redrosh4386 I understand it the first time I watched it and was able to do it no problem like 2-3 times after watching it. Is that how we learn to solve these problems. Imposter syndrome is my main source of anxiety.

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

      @@UnknownSend3r I try to solve them alone first. If figuring it out starts to take up too much of my time then I come here lol

  • @deekshaagrawal1111
    @deekshaagrawal1111 3 ปีที่แล้ว +1

    Thanks a lot for taking so much effort to explain! It was so well explained

  • @harinisivaram7907
    @harinisivaram7907 5 ปีที่แล้ว +23

    Thanks a lot @Nick..slow and neat explanation which is understandable for newbies .. please do more leetcode problem videos like this..

  • @thenotaveragejoe
    @thenotaveragejoe 3 ปีที่แล้ว +1

    That was a really good explanation! Thank you!

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

    Thanks a lot for sharing! Nice explanation.

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

    Nice and easy solution. Thanks Nick.

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

    whenever i got an problem , I got your videos explaining them to me

  • @dannielrolfe8079
    @dannielrolfe8079 4 ปีที่แล้ว +1

    Well done. Thanks for explaining this.

  • @RattanakChea
    @RattanakChea 5 ปีที่แล้ว +3

    Great explanation. Subbed.

  • @gopishivakrishna9707
    @gopishivakrishna9707 4 ปีที่แล้ว +4

    Great Explanation Nick.. Easy to understand.. Can we can comment this snippet "List prev_row = triangle.get(i - 1);", and call the triangle to get the value as "row.add(triangle.get(i - 1).get(j-1) + triangle.get(i-1).get(j));" directly.. doesn't that save memory.

  • @sowmyasg8127
    @sowmyasg8127 4 ปีที่แล้ว +1

    clean explanation thanks bro!!

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

    Awesome solution Nick

  • @sergeysachkov7388
    @sergeysachkov7388 4 ปีที่แล้ว

    Thanks man. Subscribed!

  • @ArjunKalidas
    @ArjunKalidas 4 ปีที่แล้ว +39

    You should probably use some app to draw pictures or explain like on a whiteboard before getting started with the code. Because, the moment someone sees the code, they are not gonna want to learn the actual concept and try to just copy the solution or mug up the code. Once the concept is clear, people will try to implement in various ways at least. Good job otherwise, but I know you are posting videos for free, here and so can't ask you to invest so much either. Thanks for the video man!

  • @vincent-uh5uo
    @vincent-uh5uo 3 ปีที่แล้ว

    very clear solution

  • @nayanagarwal5312
    @nayanagarwal5312 3 ปีที่แล้ว

    Thank You So Much White.

  • @logic_master950
    @logic_master950 5 ปีที่แล้ว +8

    Where have you been 😃😃😃? Thanks a lot man 👍👍👍👍👍👍👍👌👌👌

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

    Nick thanks a lot for, the crystal clear explanation. Could you also advise some kind of path/roadmap to be successful in solving such A&DS tasks? I recently completed several courses and read a book Grokking Algorithms, and currently just practicing on Leetcode.

  • @jasper5016
    @jasper5016 9 หลายเดือนก่อน

    Thanks so much!

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

    doing great job, thank you.

  • @TusharYadav-es1bq
    @TusharYadav-es1bq 4 ปีที่แล้ว

    elegant solution

  • @ashishranjan8297
    @ashishranjan8297 4 ปีที่แล้ว +1

    Nick white - boiiii - you are the best ...

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

    thanks for the video

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

    Really cool

  • @ThabiraGamingShorts
    @ThabiraGamingShorts 4 ปีที่แล้ว +1

    Hi nick...please add some more videos for leet code

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

    Thank you

  • @tejaswikolli3638
    @tejaswikolli3638 3 ปีที่แล้ว

    I know that you know that you are the best!!

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

    Iam big big big big fan of u sir🙏🙏 fan from India andhra Pradesh state

  • @karthik448
    @karthik448 4 ปีที่แล้ว +7

    If you have a linear way to convert a number's digits to csv values (121 - > 1,2,1) then you can just generate the triangle by just multiplying 11 to every row after the first one. Just thought of sharing an alternative. Awesome video as always Nick!

    • @Tresla
      @Tresla 3 ปีที่แล้ว +5

      This doesn't work past the 5th row

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

    Hello Nick, thanks for your video, but what is that row means here ,since I don’t find any initialize of any thing of that

  • @badshahshikhar7113
    @badshahshikhar7113 4 ปีที่แล้ว +1

    You r good , can you increae the font size of codeor zoom it, somehow

  • @anubhav.codess
    @anubhav.codess 6 หลายเดือนก่อน +1

    Pascals Triangle Solved Tip to remember Solve the question first for n=3

  • @modulyoutube
    @modulyoutube 5 หลายเดือนก่อน

    Awesome

  • @natsworldUS
    @natsworldUS 3 ปีที่แล้ว

    @Nick White I have a quick question at line 13. Why are the type of "prev_row" and "triangle" the same?
    List == List ????

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

      It is equal to List Inside of triangle. Before for loop started, there is a code say triangle. add(first_row). So for line 13, it is equivalent to the same type of array list which is List since the triangle was getting the List from itself

  • @badbaboye
    @badbaboye 6 หลายเดือนก่อน

    great

  • @saxena3718
    @saxena3718 3 ปีที่แล้ว +1

    did same ..getting index out of bounds

  • @prabhanjan1505
    @prabhanjan1505 4 ปีที่แล้ว

    You are a fucking lifesaver man thanks a lot

  • @mallasatyanarayana1942
    @mallasatyanarayana1942 4 ปีที่แล้ว

    Super bro

  • @omaryahia
    @omaryahia 17 วันที่ผ่านมา

    nice 🌟

  • @anjalisingh-sx5ct
    @anjalisingh-sx5ct 3 ปีที่แล้ว

    We have used generate in first line but didn't used later? Plz help me to get this thing??

  • @ashishverma4932
    @ashishverma4932 4 ปีที่แล้ว +3

    how do you got so good in dsa

  • @neerajverma9226
    @neerajverma9226 3 ปีที่แล้ว

    Can you solve it using recursion?

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

    👍

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

    @nick for first row how get(0) and get(1) works?

    • @vamshikrishna8143
      @vamshikrishna8143 4 ปีที่แล้ว +1

      For first row, we are not doing inner for loop. First row is added manually

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

      You do not get(o) or get(1) on the first row. On the first loop, i = j = 1 so the inner for loop is skipped and we add the second 1 manually.

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

      I had the same question

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

    we just need to raise 11 to the row numbers
    11^0=1
    11^1=11
    11^2=121
    11^3=1331
    and that's it

  • @husniddinqurbonboyev2634
    @husniddinqurbonboyev2634 4 ปีที่แล้ว

    Run time - 1ms. How it is possible?

  • @driftkinganeezy
    @driftkinganeezy 5 ปีที่แล้ว +1

    why did you do firstrow.add(row) when row wasn't defined anywhere?

    • @NickWhite
      @NickWhite  5 ปีที่แล้ว +6

      that was a mistake that i fixed at the end of the video

    • @driftkinganeezy
      @driftkinganeezy 5 ปีที่แล้ว +3

      @@NickWhite lol for sure, i just saw it get fixed at the end

    • @navinchainani4721
      @navinchainani4721 4 ปีที่แล้ว

      Anir plz tell why numsrows== 0 return triangle plz explain this line

    • @ignaciocrinigan7810
      @ignaciocrinigan7810 4 ปีที่แล้ว +1

      @@navinchainani4721 if you are asking to generate a triangle with 0 rows (numrows == 0), then you return a void triangle (initialized on line 6)

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

    Why do you write row in brackets of the 9 th line

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

      First row contains only 1 element '1'. Which is equal to row number '1'. Hence , u can write .add(row) or .add(1)

  • @TimsDaBossMC
    @TimsDaBossMC 3 ปีที่แล้ว

    The reason this works is because the elements initialize at zero correct?

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

    11^x method
    var A=[1,1,0]
    var B=[0,1,1]
    Var C= A+B=[1,2,1]
    Print Var C
    Var A=Var C + right append 0
    Var B=Var C + left append 0
    Var C=A+B=[1,3,3,1]
    Print Var C
    .....etc

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

    Just started your videos but why are mixing snake and camel case? Are you a python or Java programmer?

  • @MaminaZvezdochka
    @MaminaZvezdochka 3 ปีที่แล้ว

    🤍 thanks

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

    Why is this problem under dynamic programming? The only way to solve this is pretty much brute force. Or am I dumb?

  • @mohammedomor1458
    @mohammedomor1458 4 ปีที่แล้ว +1

    I have to ask, what's with the clap?

  • @DeeneeKingz
    @DeeneeKingz 8 หลายเดือนก่อน

    w

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

    Code source plz

  • @kavyabanka4482
    @kavyabanka4482 11 หลายเดือนก่อน

    your are so talented and soooo handsome Love from India

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

    public static int[ ][ ] theSolution(int numberOfRows) {
    int[ ][ ] pascals_triangle = new int[numberOfRows][ ];
    for (int i = 0; i < numberOfRows; i++) {
    int numberOfCellsInCurrentRow = i+1;
    pascals_triangle[i] = new int[numberOfCellsInCurrentRow];
    for (int j = 0; j < numberOfCellsInCurrentRow; j++) {
    boolean isFirstCell = 0 == j;
    boolean isLastCell = numberOfCellsInCurrentRow - 1 == j;
    if(isFirstCell || isLastCell) { pascals_triangle[i][j] = 1; }
    else {
    int a = pascals_triangle[i-1][j-1];
    int b = pascals_triangle[i-1][j];
    pascals_triangle[i][j] = a + b;
    }
    }
    }
    return pascals_triangle;
    }
    // Test Case
    int test1 = 5;
    int[ ][ ] theAnswer = theSolution(test1);
    int[ ][ ] expected = {
    { 1 },
    { 1, 1 },
    { 1, 2, 1 },
    { 1, 3, 3, 1 },
    { 1, 4, 6, 4, 1 },
    };
    System.out.println(Arrays.deepToString(theAnswer));

  • @BcomingHIM
    @BcomingHIM 3 ปีที่แล้ว

    You kinda look and talk like Big Head from silicon valley😅

  • @priyankareddy7408
    @priyankareddy7408 3 ปีที่แล้ว

    Thank you

  • @ROHIT-gv7xk
    @ROHIT-gv7xk 3 ปีที่แล้ว

    great

  • @karthik448
    @karthik448 4 ปีที่แล้ว +1

    If you have a linear way to convert a number's digits to csv values (121 - > 1,2,1) then you can just generate the triangle by just multiplying 11 to every row after the first one. Just thought of sharing an alternative. Awesome video as always Nick!

    • @dileshsolanki2383
      @dileshsolanki2383 4 ปีที่แล้ว +3

      // Liked your alternative hence gave a try.
      List triangle = new ArrayList();
      int n = 5;
      List first = new ArrayList();
      first.add("1");
      triangle.add(first);
      for (int i = 1; i < n; i++) {
      List l = new ArrayList();
      l.add(Integer.toString((Integer.parseInt(triangle.get(i - 1).get(0).replaceAll(",", "")) * 11))
      .replaceAll("(\\d)(?=(\\d{1})+$)", "$1,"));
      /* above line would first get the prev object in the list and the first element and remove comma if any, then convert to an integer, multiply by 11. Then again add a comma after each digit (hunted online for regex & played around) and add to list by converting back to a string. */
      triangle.add(l);
      }
      triangle.stream().forEach(System.out::println);