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 - วิทยาศาสตร์และเทคโนโลยี
I love how you quickly go through the algorithm without getting slowed down by overly simplified explanations. Perfect pace. Love it!
tru
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.
Great explanation!! Really loved how you explained everything to the minute details for programming beginners like me. Subbed, thanks!❤
Big Respect from Ethiopia!, Nick the way you make things as simple as possible but to the very point is just superb!
Thanks for sharing! This code is clear and well presented
after 4 years and you still earnings subscribers and respect , i really like you man , thanks for those helpfull videos
Hey nick your algorithm videos are just great.
Damn this question was lowkey hard.
all are lowkey "hard"
@@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 ?
@@UnknownSend3r if you understand it , and you can write the code without copying it then its okay .
@@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.
@@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
Thanks a lot for taking so much effort to explain! It was so well explained
Thanks a lot @Nick..slow and neat explanation which is understandable for newbies .. please do more leetcode problem videos like this..
That was a really good explanation! Thank you!
Thanks a lot for sharing! Nice explanation.
Nice and easy solution. Thanks Nick.
whenever i got an problem , I got your videos explaining them to me
Well done. Thanks for explaining this.
Great explanation. Subbed.
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.
clean explanation thanks bro!!
Awesome solution Nick
Thanks man. Subscribed!
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!
very clear solution
Thank You So Much White.
Where have you been 😃😃😃? Thanks a lot man 👍👍👍👍👍👍👍👌👌👌
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.
Thanks so much!
doing great job, thank you.
elegant solution
Nick white - boiiii - you are the best ...
thanks for the video
Really cool
Hi nick...please add some more videos for leet code
Thank you
I know that you know that you are the best!!
Iam big big big big fan of u sir🙏🙏 fan from India andhra Pradesh state
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!
This doesn't work past the 5th row
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
You r good , can you increae the font size of codeor zoom it, somehow
Pascals Triangle Solved Tip to remember Solve the question first for n=3
Awesome
@Nick White I have a quick question at line 13. Why are the type of "prev_row" and "triangle" the same?
List == List ????
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
great
did same ..getting index out of bounds
You are a fucking lifesaver man thanks a lot
Super bro
nice 🌟
We have used generate in first line but didn't used later? Plz help me to get this thing??
how do you got so good in dsa
Can you solve it using recursion?
👍
@nick for first row how get(0) and get(1) works?
For first row, we are not doing inner for loop. First row is added manually
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.
I had the same question
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
11^5 = 161051
Run time - 1ms. How it is possible?
why did you do firstrow.add(row) when row wasn't defined anywhere?
that was a mistake that i fixed at the end of the video
@@NickWhite lol for sure, i just saw it get fixed at the end
Anir plz tell why numsrows== 0 return triangle plz explain this line
@@navinchainani4721 if you are asking to generate a triangle with 0 rows (numrows == 0), then you return a void triangle (initialized on line 6)
Why do you write row in brackets of the 9 th line
First row contains only 1 element '1'. Which is equal to row number '1'. Hence , u can write .add(row) or .add(1)
The reason this works is because the elements initialize at zero correct?
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
Just started your videos but why are mixing snake and camel case? Are you a python or Java programmer?
🤍 thanks
Why is this problem under dynamic programming? The only way to solve this is pretty much brute force. Or am I dumb?
I have to ask, what's with the clap?
w
Code source plz
your are so talented and soooo handsome Love from India
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));
You kinda look and talk like Big Head from silicon valley😅
Thank you
great
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!
// 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);