LeetCode Pascal's Triangle Solution Explained - Java

  Рет қаралды 150,273

Nick White

Nick White

5 жыл бұрын

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 Жыл бұрын
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 жыл бұрын
love and respect from India. there are thousand of teachers/professionals doing the same thing on KZbin, but still you got something which keeps me bounded to this channel.Thank you for making such great explanatory videos.
@sk8tergal995
@sk8tergal995 4 жыл бұрын
Great explanation!! Really loved how you explained everything to the minute details for programming beginners like me. Subbed, thanks!❤
@ArjunKalidas
@ArjunKalidas 4 жыл бұрын
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!
@hacker-7214
@hacker-7214 4 жыл бұрын
Damn this question was lowkey hard.
@rodanm
@rodanm 3 жыл бұрын
all are lowkey "hard"
@UnknownSend3r
@UnknownSend3r 2 жыл бұрын
@@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 жыл бұрын
@@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
@harinisivaram7907
@harinisivaram7907 5 жыл бұрын
Thanks a lot @Nick..slow and neat explanation which is understandable for newbies .. please do more leetcode problem videos like this..
@gopishivakrishna9707
@gopishivakrishna9707 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.
@fangzhang7434
@fangzhang7434 5 жыл бұрын
Thanks for sharing! This code is clear and well presented
@AdtecBarema
@AdtecBarema Жыл бұрын
Big Respect from Ethiopia!, Nick the way you make things as simple as possible but to the very point is just superb!
@deekshaagrawal1111
@deekshaagrawal1111 3 жыл бұрын
Thanks a lot for taking so much effort to explain! It was so well explained
@isssamsam8623
@isssamsam8623 10 ай бұрын
after 4 years and you still earnings subscribers and respect , i really like you man , thanks for those helpfull videos
@nidhiverma0203
@nidhiverma0203 2 жыл бұрын
Hey nick your algorithm videos are just great.
@thenotaveragejoe
@thenotaveragejoe 3 жыл бұрын
That was a really good explanation! Thank you!
@zhihaoli3732
@zhihaoli3732 5 жыл бұрын
Thanks a lot for sharing! Nice explanation.
@dannielrolfe8079
@dannielrolfe8079 4 жыл бұрын
Well done. Thanks for explaining this.
@amitbhattacharya356
@amitbhattacharya356 2 жыл бұрын
Nice and easy solution. Thanks Nick.
@RattanakChea
@RattanakChea 5 жыл бұрын
Great explanation. Subbed.
@sarvarkhalimov111
@sarvarkhalimov111 2 жыл бұрын
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.
@sowmyasg8127
@sowmyasg8127 4 жыл бұрын
clean explanation thanks bro!!
@karthik448
@karthik448 4 жыл бұрын
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 жыл бұрын
This doesn't work past the 5th row
@sergeysachkov7388
@sergeysachkov7388 4 жыл бұрын
Thanks man. Subscribed!
@039saranshvashisht8
@039saranshvashisht8 2 жыл бұрын
whenever i got an problem , I got your videos explaining them to me
@davidhackro1425
@davidhackro1425 2 жыл бұрын
Awesome solution Nick
@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
@logic_master950
@logic_master950 5 жыл бұрын
Where have you been 😃😃😃? Thanks a lot man 👍👍👍👍👍👍👍👌👌👌
@nayanagarwal5312
@nayanagarwal5312 3 жыл бұрын
Thank You So Much White.
@ThabiraGamingShorts
@ThabiraGamingShorts 4 жыл бұрын
Hi nick...please add some more videos for leet code
@vincent-uh5uo
@vincent-uh5uo 3 жыл бұрын
very clear solution
@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
@shivanshutripathi8985
@shivanshutripathi8985 Жыл бұрын
doing great job, thank you.
@jasper5016
@jasper5016 9 ай бұрын
Thanks so much!
@TusharYadav-es1bq
@TusharYadav-es1bq 4 жыл бұрын
elegant solution
@ashishranjan8297
@ashishranjan8297 4 жыл бұрын
Nick white - boiiii - you are the best ...
@arjunsumanth1394
@arjunsumanth1394 3 жыл бұрын
Iam big big big big fan of u sir🙏🙏 fan from India andhra Pradesh state
@shelly6812
@shelly6812 5 жыл бұрын
Really cool
@badshahshikhar7113
@badshahshikhar7113 4 жыл бұрын
You r good , can you increae the font size of codeor zoom it, somehow
@anjalisingh-sx5ct
@anjalisingh-sx5ct 3 жыл бұрын
We have used generate in first line but didn't used later? Plz help me to get this thing??
@pablohernandez4305
@pablohernandez4305 2 жыл бұрын
thanks for the video
@saxena3718
@saxena3718 3 жыл бұрын
did same ..getting index out of bounds
@tejaswikolli3638
@tejaswikolli3638 3 жыл бұрын
I know that you know that you are the best!!
@shrirambalaji2915
@shrirambalaji2915 Жыл бұрын
Thank you
@anubhav.codess
@anubhav.codess 6 ай бұрын
Pascals Triangle Solved Tip to remember Solve the question first for n=3
@ashishverma4932
@ashishverma4932 4 жыл бұрын
how do you got so good in dsa
@neerajverma9226
@neerajverma9226 3 жыл бұрын
Can you solve it using recursion?
@jamarimcfarlane4844
@jamarimcfarlane4844 2 жыл бұрын
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
@kawaiicowboy1774
@kawaiicowboy1774 Жыл бұрын
11^5 = 161051
@tabraizahmad7876
@tabraizahmad7876 4 жыл бұрын
@nick for first row how get(0) and get(1) works?
@vamshikrishna8143
@vamshikrishna8143 4 жыл бұрын
For first row, we are not doing inner for loop. First row is added manually
@nick2629
@nick2629 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
@rydmerlin
@rydmerlin Жыл бұрын
Just started your videos but why are mixing snake and camel case? Are you a python or Java programmer?
@prabhanjan1505
@prabhanjan1505 4 жыл бұрын
You are a fucking lifesaver man thanks a lot
@husniddinqurbonboyev2634
@husniddinqurbonboyev2634 4 жыл бұрын
Run time - 1ms. How it is possible?
@taran7649
@taran7649 2 жыл бұрын
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)
@driftkinganeezy
@driftkinganeezy 5 жыл бұрын
why did you do firstrow.add(row) when row wasn't defined anywhere?
@NickWhite
@NickWhite 5 жыл бұрын
that was a mistake that i fixed at the end of the video
@driftkinganeezy
@driftkinganeezy 5 жыл бұрын
@@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 жыл бұрын
@@navinchainani4721 if you are asking to generate a triangle with 0 rows (numrows == 0), then you return a void triangle (initialized on line 6)
@modulyoutube
@modulyoutube 5 ай бұрын
Awesome
@badbaboye
@badbaboye 6 ай бұрын
great
@TimsDaBossMC
@TimsDaBossMC 3 жыл бұрын
The reason this works is because the elements initialize at zero correct?
@omaryahia
@omaryahia 21 күн бұрын
nice 🌟
@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?
@mallasatyanarayana1942
@mallasatyanarayana1942 4 жыл бұрын
Super bro
@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
@mohammedomor1458
@mohammedomor1458 4 жыл бұрын
I have to ask, what's with the clap?
@frodo774
@frodo774 Жыл бұрын
👍
@firasgorrab6050
@firasgorrab6050 Жыл бұрын
Code source plz
@MaminaZvezdochka
@MaminaZvezdochka 3 жыл бұрын
🤍 thanks
@kavyabanka4482
@kavyabanka4482 11 ай бұрын
your are so talented and soooo handsome Love from India
@DeeneeKingz
@DeeneeKingz 8 ай бұрын
w
@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😅
@karthik448
@karthik448 4 жыл бұрын
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 жыл бұрын
// 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);
@priyankareddy7408
@priyankareddy7408 3 жыл бұрын
Thank you
@ROHIT-gv7xk
@ROHIT-gv7xk 3 жыл бұрын
great
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 345 М.
Pascal's Triangle - Leetcode 118 - Python
8:41
NeetCode
Рет қаралды 86 М.
Nutella bro sis family Challenge 😋
00:31
Mr. Clabik
Рет қаралды 14 МЛН
Жайдарман | Туған күн 2024 | Алматы
2:22:55
Jaidarman OFFICIAL / JCI
Рет қаралды 1,8 МЛН
KINDNESS ALWAYS COME BACK
00:59
dednahype
Рет қаралды 157 МЛН
WHO LAUGHS LAST LAUGHS BEST 😎 #comedy
00:18
HaHaWhat
Рет қаралды 22 МЛН
LeetCode Contains Duplicate Solution Explained - Java
5:28
Nick White
Рет қаралды 97 М.
LeetCode 48. Rotate Image (Solution Explained)
10:18
Nick White
Рет қаралды 84 М.
Climbing Stairs
5:35
Kevin Naughton Jr.
Рет қаралды 99 М.
LeetCode 3Sum Solution Explained - Java
10:00
Nick White
Рет қаралды 195 М.
Why You Can't Solve Leetcode Problems
11:35
Bradley Allen
Рет қаралды 31 М.
System Design Interview - Rate Limiting (local and distributed)
34:36
System Design Interview
Рет қаралды 289 М.
How to Do 90% of What Plugins Do (With Just Vim)
1:14:03
thoughtbot
Рет қаралды 874 М.
Как удвоить напряжение? #электроника #умножитель
1:00
Hi Dev! – Электроника
Рет қаралды 843 М.
😱Хакер взломал зашифрованный ноутбук.
0:54
Последний Оплот Безопасности
Рет қаралды 867 М.
⚡️Супер БЫСТРАЯ Зарядка | Проверка
1:00
НЕ ПОКУПАЙ СМАРТФОН, ПОКА НЕ УЗНАЕШЬ ЭТО! Не ошибись с выбором…
15:23
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 6 МЛН
Battery  low 🔋 🪫
0:10
dednahype
Рет қаралды 10 МЛН