Тёмный

LeetCode Pascal's Triangle Solution Explained - Java 

Nick White
Подписаться 378 тыс.
Просмотров 151 тыс.
50% 1

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

Наука

Опубликовано:

 

15 янв 2019

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 88   
@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 RU-vid, 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!❤
@AdtecBarema
@AdtecBarema Год назад
Big Respect from Ethiopia!, Nick the way you make things as simple as possible but to the very point is just superb!
@harinisivaram7907
@harinisivaram7907 5 лет назад
Thanks a lot @Nick..slow and neat explanation which is understandable for newbies .. please do more leetcode problem videos like this..
@fangzhang7434
@fangzhang7434 5 лет назад
Thanks for sharing! This code is clear and well presented
@deekshaagrawal1111
@deekshaagrawal1111 3 года назад
Thanks a lot for taking so much effort to explain! It was so well explained
@nidhiverma0203
@nidhiverma0203 2 года назад
Hey nick your algorithm videos are just great.
@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.
@thenotaveragejoe
@thenotaveragejoe 3 года назад
That was a really good explanation! Thank you!
@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
@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!
@zhihaoli3732
@zhihaoli3732 5 лет назад
Thanks a lot for sharing! Nice explanation.
@amitbhattacharya356
@amitbhattacharya356 2 года назад
Nice and easy solution. Thanks Nick.
@RattanakChea
@RattanakChea 5 лет назад
Great explanation. Subbed.
@dannielrolfe8079
@dannielrolfe8079 4 года назад
Well done. Thanks for explaining this.
@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!!
@davidhackro1425
@davidhackro1425 2 года назад
Awesome solution Nick
@sergeysachkov7388
@sergeysachkov7388 4 года назад
Thanks man. Subscribed!
@039saranshvashisht8
@039saranshvashisht8 2 года назад
whenever i got an problem , I got your videos explaining them to me
@logic_master950
@logic_master950 5 лет назад
Where have you been 😃😃😃? Thanks a lot man 👍👍👍👍👍👍👍👌👌👌
@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
@nayanagarwal5312
@nayanagarwal5312 3 года назад
Thank You So Much White.
@vincent-uh5uo
@vincent-uh5uo 4 года назад
very clear solution
@ThabiraGamingShorts
@ThabiraGamingShorts 4 года назад
Hi nick...please add some more videos for leet code
@shelly6812
@shelly6812 5 лет назад
Really cool
@jasper5016
@jasper5016 10 месяцев назад
Thanks so much!
@TusharYadav-es1bq
@TusharYadav-es1bq 4 года назад
elegant solution
@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
@shivanshutripathi8985
@shivanshutripathi8985 Год назад
doing great job, thank you.
@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
@ashishranjan8297
@ashishranjan8297 4 года назад
Nick white - boiiii - you are the best ...
@pablohernandez4305
@pablohernandez4305 2 года назад
thanks for the video
@priyankareddy7408
@priyankareddy7408 3 года назад
Thank you
@arjunsumanth1394
@arjunsumanth1394 3 года назад
Iam big big big big fan of u sir🙏🙏 fan from India andhra Pradesh state
@badshahshikhar7113
@badshahshikhar7113 4 года назад
You r good , can you increae the font size of codeor zoom it, somehow
@tejaswikolli3638
@tejaswikolli3638 3 года назад
I know that you know that you are the best!!
@neerajverma9226
@neerajverma9226 3 года назад
Can you solve it using recursion?
@anjalisingh-sx5ct
@anjalisingh-sx5ct 4 года назад
We have used generate in first line but didn't used later? Plz help me to get this thing??
@ashishverma4932
@ashishverma4932 4 года назад
how do you got so good in dsa
@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
@saxena3718
@saxena3718 3 года назад
did same ..getting index out of bounds
@modulyoutube
@modulyoutube 6 месяцев назад
Awesome
@anubhav.codess
@anubhav.codess 7 месяцев назад
Pascals Triangle Solved Tip to remember Solve the question first for n=3
@ROHIT-gv7xk
@ROHIT-gv7xk 3 года назад
great
@mallasatyanarayana1942
@mallasatyanarayana1942 4 года назад
Super bro
@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)
@omaryahia
@omaryahia Месяц назад
nice 🌟
@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?
@TimsDaBossMC
@TimsDaBossMC 3 года назад
The reason this works is because the elements initialize at zero correct?
@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?
@michaelhunter8006
@michaelhunter8006 3 года назад
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?
@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
@firasgorrab6050
@firasgorrab6050 Год назад
Code source plz
@frodo774
@frodo774 Год назад
👍
@MaminaZvezdochka
@MaminaZvezdochka 3 года назад
🤍 thanks
@kavyabanka4482
@kavyabanka4482 Год назад
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😅
@shrirambalaji2915
@shrirambalaji2915 Год назад
Thank you
@badbaboye
@badbaboye 7 месяцев назад
great
@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);
Далее
LeetCode 55. Jump Game (Algorithm Explained)
10:06
Просмотров 77 тыс.
How I would learn Leetcode if I could start over
18:03
Просмотров 398 тыс.
8 patterns to solve 80% Leetcode problems
7:30
Просмотров 286 тыс.
How I Coded An Entire Game Using ChatGPT
19:48
Просмотров 121 тыс.
#samsung #retrophone #nostalgia #x100
0:14
Просмотров 14 млн
iPhone socket cleaning #Fixit
0:30
Просмотров 18 млн