Pascal's Triangle II - Leetcode 119 - Python

  Рет қаралды 13,790

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 19
@m.kamalali
@m.kamalali Жыл бұрын
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
@commonguy7
@commonguy7 6 ай бұрын
fkin genious bro
@VidyaBhandary
@VidyaBhandary Жыл бұрын
A Q&A video and two problems .. you are on a roll. Thanks for making these videos !
@YehorKozyr
@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.
@pbenikovszky1
@pbenikovszky1 4 ай бұрын
sure, and the cpu will easily handle rowindex 1000 :D
@sickboydroid
@sickboydroid 2 ай бұрын
@@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
@rajanmaheshwari Жыл бұрын
Just did this few hours back 😃
@xaceffulgent
@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
@chuckle_pugz96 Жыл бұрын
'cause leetcode is passing all the inputs to this class in the background. Though some sites just use a function.
@krateskim4169
@krateskim4169 Жыл бұрын
Awesome solution
@ashesh8085
@ashesh8085 7 ай бұрын
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
@Mercer80 Жыл бұрын
C++ class Solution { public: vector getRow(int rowIndex) { vectorprev(rowIndex+1); for(int r=0;r
@bud2725
@bud2725 6 ай бұрын
hi @NeetCodeIO code isn't working for current format of the question Leetcode 119. Code returns [1] always. Can you please check? Thank you
@AustinWeeks
@AustinWeeks 4 ай бұрын
my friend you have to figure it out on your own sometimes
@waqasbutt61
@waqasbutt61 7 күн бұрын
you need to reassign res = next_row after the end of the inner for loop
@reqzonegaming7157
@reqzonegaming7157 Жыл бұрын
Please Bro Make video for 2905. Find Indices With Index and Value Difference II
@MrBomb72
@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
@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]
@sickboydroid
@sickboydroid 2 ай бұрын
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
Backspace String Compare - Leetcode 844 - Python
14:10
NeetCodeIO
Рет қаралды 17 М.
Pascal's Triangle - Leetcode 118 - Python
8:41
NeetCode
Рет қаралды 104 М.
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
📱 AI Chat Bot • Claude x Flutter Tutorial
15:34
Mitch Koko
Рет қаралды 2,7 М.
Champagne Tower - Leetcode 799 - Python
13:48
NeetCodeIO
Рет қаралды 13 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 239 М.
Pascal Triangle | Finding nCr in minimal time
26:45
take U forward
Рет қаралды 322 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 916 М.
Deepseek Changes Everything
10:26
NeetCodeIO
Рет қаралды 82 М.
Extra Characters in a String - Leetcode 2707 - Python
21:11
NeetCodeIO
Рет қаралды 19 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 827 М.
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН