We can do the follow up using only 1 array by updating the array backward row=[1] for i in range(rowIndex): row.append(1) for j in range(i,0,-1): row[j]+=row[j-1] return row
@commonguy76 ай бұрын
fkin genious bro
@VidyaBhandary Жыл бұрын
A Q&A video and two problems .. you are on a roll. Thanks for making these videos !
@YehorKozyr Жыл бұрын
This solution works, but it doesn't cover the mathematical meaning of Pascal's triangle and therefore can be simplified into a time and space O(rowIndex) function with a calculation of binomial coefficients.
@pbenikovszky14 ай бұрын
sure, and the cpu will easily handle rowindex 1000 :D
@sickboydroid2 ай бұрын
@@pbenikovszky1 there is a easier way to calculate binomial coefficients without calculating factorials. Here is js version: function nCr(n, r) { if(r === 0 || n === r) return 1; if(r > n/2) r = n-r; let res = 1; for(let i = 1; i
@rajanmaheshwari Жыл бұрын
Just did this few hours back 😃
@xaceffulgent Жыл бұрын
Discovered this channel recently and am learning a lot! Thank you! Beginner question: why do you put your sol in a class?
@chuckle_pugz96 Жыл бұрын
'cause leetcode is passing all the inputs to this class in the background. Though some sites just use a function.
@krateskim4169 Жыл бұрын
Awesome solution
@ashesh80857 ай бұрын
My approach to this problem was to try to figure out a function such that: f(n, i) = ans[i] ; Meaning there would be a function which when given the rowIndex would be able to calculate the value of i th element in the row. Does a function like this exist? Is it even possible? This to me would seem much more efficient. Here are some examples of this functions: f(5,5) = 1 f(4,2) = 6 f(5,2) = 10 f(5,3) = 10 f(n, 0) = 1 f(n, n) = 1 .... etc. Update: This is the binomial coefficient function
@Mercer80 Жыл бұрын
C++ class Solution { public: vector getRow(int rowIndex) { vectorprev(rowIndex+1); for(int r=0;r
@bud27256 ай бұрын
hi @NeetCodeIO code isn't working for current format of the question Leetcode 119. Code returns [1] always. Can you please check? Thank you
@AustinWeeks4 ай бұрын
my friend you have to figure it out on your own sometimes
@waqasbutt617 күн бұрын
you need to reassign res = next_row after the end of the inner for loop
@reqzonegaming7157 Жыл бұрын
Please Bro Make video for 2905. Find Indices With Index and Value Difference II
@MrBomb72 Жыл бұрын
There’s a good quality one here: kzbin.info/www/bejne/f32UgXVun9OZnqcfeature=shared (found this from the top rated post under the solutions tab)
@infoknow3278 Жыл бұрын
Easiest to come up with class Solution: def getRow(self, rowIndex: int) -> List[int]: res = [[1]] for i in range(rowIndex): tmp = [0] + res[-1] + [0] row = [] for j in range(len(res[-1])+1): row.append(tmp[j]+tmp[j+1]) res.append(row) return res[rowIndex]
@sickboydroid2 ай бұрын
for math nerds: ---------------------------------------------------------------- TC: O(rowIndex) SC: O(rowIndex) ---------------------------------------------------------------- var getRow = function(rowIndex) { if(rowIndex === 0) return [1]; const row = new Array(rowIndex+1); for(let i = 0; i n/2) r = n-r; let res = 1; for(let i = 1; i