Pascal Triangle | Finding nCr in minimal time

Pascal Triangle | Finding nCr in minimal time

take U forward

1 год назад

159,238 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@ArpanChakraborty-do6yz
@ArpanChakraborty-do6yz - 11.01.2024 21:23

🥰🥰😘😘

Ответить
@vigneshkumarganesan1529
@vigneshkumarganesan1529 - 06.01.2024 08:20

I don't get the point where he bring the formula. How did he arrive that formula will give the output? anyone knows the answer?

Ответить
@akhilmittal2762
@akhilmittal2762 - 04.01.2024 19:34

can we do it with that apprach as we have seen them as the square , cube and quadraple of 11 as 11,121,1331....and so on so we first convert that no . to string and then string to that vector and then print:)
this will take as overall complexity of O(N) in worst case

Ответить
@gokulakumar7658
@gokulakumar7658 - 27.12.2023 03:56

How about this? This is the 3rd type - print the entire triangle and I believe this is also O(n^2) solution (can someone please confirm?). I came up with this in Leetcode before watching the solution video.

class Solution {
public:
vector<vector<int>> generate(int numRows) {
std::vector<std::vector<int>> result;
result.reserve(numRows);
result.push_back({1});

for (int i = 0; i < numRows - 1; i++) {
std::vector <int> vals;
vals.reserve(i+1);
vals.push_back(1);
for (int j = 1; j < result[i].size(); j++) {
auto val = result[i][j-1] + result[i][j];
vals.push_back(val);
}
vals.push_back(1);
result.push_back(vals);
}
return result;
}
};

Ответить
@RituSingh-ne1mk
@RituSingh-ne1mk - 22.12.2023 14:26

Understood!

Ответить
@user-st9ff2vh6l
@user-st9ff2vh6l - 21.12.2023 16:25

Understood

Ответить
@yasaswiv2030
@yasaswiv2030 - 21.12.2023 09:26

we can use recursion right ??
generate the answer for N-1 and the add another row by with the help of last row of generated answer and add this row and return the final answer

Ответить
@dewanandkumar8589
@dewanandkumar8589 - 16.12.2023 13:31

Understood

Ответить
@firebout7675
@firebout7675 - 12.12.2023 22:42

understood

Ответить
@impostermamu4597
@impostermamu4597 - 12.12.2023 11:55

java soln?

Ответить
@sumitworld918
@sumitworld918 - 03.12.2023 08:46

Understood ❤

Ответить
@shrutisrivastava7174
@shrutisrivastava7174 - 25.11.2023 08:23

Really amazed by ur Intelligence but i don't know why i am not think this kind of solution on my own why 😭😭😭

Ответить
@abhisheksa6635
@abhisheksa6635 - 21.11.2023 16:17

Love it

Ответить
@jineshnadar6409
@jineshnadar6409 - 15.11.2023 09:20

Printing Pascal triangle using DP

vector<vector<int>> generate(int numRows) {
vector<int>firstRow { 1 };
vector<vector<int>> ans;
ans.push_back( firstRow );
for( int row = 2 ; row <= numRows; row++ )
{
vector<int> lastRow = ans.back();

vector<int> newRow;
newRow.push_back( 1 );

for( int i = 1; i <= row - 2; i++ )
{
newRow.push_back( lastRow[ i - 1] + lastRow[ i ] );
}
newRow.push_back( 1 );
ans.push_back( newRow );
}

Ответить
@udaykiranmogalpau8292
@udaykiranmogalpau8292 - 13.11.2023 17:43

understood

Ответить
@user-nl2zp1qh6n
@user-nl2zp1qh6n - 11.11.2023 14:20

understood

Ответить
@complexcat6329
@complexcat6329 - 01.11.2023 16:46

understood, thank you!

Ответить
@shibasishdas4107
@shibasishdas4107 - 31.10.2023 18:10

public List<List<Integer>> generate(int numRows) {
List<List<Integer>> outer = new ArrayList<>();
int i = 0;

List<Integer> x = new ArrayList<Integer>();
x.add(1);
outer.add(x);

while(i < numRows - 1) {
List<Integer> inner = new ArrayList<Integer>();
inner.add(1);

List<Integer> last = outer.get(outer.size() - 1);

for(int j = 0; j <= last.size() - 2; j++) {
inner.add(last.get(j) + last.get(j+1));
}

inner.add(1);

outer.add(inner);
i++;
}
return outer;
}

What do you think about this solution? As i can see the complexity is O(r*c)?

Ответить
@user-quietwicked
@user-quietwicked - 26.10.2023 22:04

understood

Ответить
@YourCodeVerse
@YourCodeVerse - 26.10.2023 06:51

Understood✅🔥🔥

Ответить
@dishaparwani6711
@dishaparwani6711 - 24.10.2023 15:24

class Solution{
public:

vector<ll> generateRow(int row) {
long long ans = 1;
vector<ll> ansRow;
ansRow.push_back(1); //inserting the 1st element

//calculate the rest of the elements:
for (int col = 1; col < row; col++) {
ans = (ans * (row - col)));
ans = (ans / col));
ansRow.push_back(ans);
}
return ansRow;
}

vector<ll> nthRowOfPascalTriangle(int n) {
// code here
vector<vector<ll>> ans;

//store the entire pascal's triangle:
for (int row = 1; row <= n; row++) {
ans.push_back(generateRow(row));
}
return ans[n-1];
}
};

It is failing for n=74 for me. Don't know what is going wrong. Can someone please help

Ответить
@sumanth2888
@sumanth2888 - 24.10.2023 09:39

understood

Ответить
@AzizurRahaman-zq4io
@AzizurRahaman-zq4io - 22.10.2023 20:53

Understood

Ответить
@culeforever5408
@culeforever5408 - 21.10.2023 09:54

understood 😇

Ответить
@user-bd9en5yo3i
@user-bd9en5yo3i - 14.10.2023 14:48

understood

Ответить
@infinitecodes
@infinitecodes - 12.10.2023 15:32

Thank you very much for this amazing course 🎉❤

Ответить
@AbjSir
@AbjSir - 10.10.2023 06:06

understood

Ответить
@Code_Solver
@Code_Solver - 09.10.2023 06:27

🎉

Ответить
@prakharkulshrestha8467
@prakharkulshrestha8467 - 30.09.2023 07:14

Understood

Ответить
@user-zz1is4yu4b
@user-zz1is4yu4b - 25.09.2023 09:51

why didnt his code on screen not work and in notes there were 2 loops

Ответить
@senseiAree
@senseiAree - 18.09.2023 17:43

Understood <3

Ответить
@csea_37_shayoribhowmick53
@csea_37_shayoribhowmick53 - 18.09.2023 16:33

Understood watching once more for being more clear

Ответить
@rishabhupadhyay8165
@rishabhupadhyay8165 - 18.09.2023 08:22

Thanks

Ответить
@quangdungo3847
@quangdungo3847 - 13.09.2023 20:00

Understood!

Ответить
@vaibhavnayak3416
@vaibhavnayak3416 - 11.09.2023 09:02

understood

Ответить
@the_mysterious_guy
@the_mysterious_guy - 10.09.2023 11:42

Understood

Ответить
@princeeshah5229
@princeeshah5229 - 09.09.2023 18:44

Understood❤❤❤❤❤

Ответить
@akashkumarmaurya2319
@akashkumarmaurya2319 - 07.09.2023 21:48

very very easy solutoion ..every time i can think about only brute solution but u gived both the solution at same time which is fantastic ...amazing love the way you teach

Ответить
@abusufyanmalik
@abusufyanmalik - 05.09.2023 20:41

Python Solution
from typing import *

def pascalTriangle(n : int) -> List[List[int]]:

def generateRow(row):
ans=1
ansRow=[]
ansRow.append(1)
for col in range (1, row):
ans=ans*(row-col)
ans=ans//col
ansRow.append(ans)
return ansRow

res=[[1]]
for i in range (2, n+1):
res.append(generateRow(i))
return res

Ответить
@CrazyBoy-zg9uz
@CrazyBoy-zg9uz - 04.09.2023 06:26

Understood 🎉

Ответить
@sachinsoma5757
@sachinsoma5757 - 03.09.2023 11:12

class Solution {
public List<List<Integer>> generate(int numRows) {
List<List<Integer>> result = new ArrayList<>(numRows);

if(numRows ==0 ) return result;
for(int i = 0;i<numRows;i++){
List<Integer> row = new ArrayList<>(i+1);
for(int j = 0;j<=i;j++){
if (j == 0 || j == i) {
row.add(1);
} else if(i>1) {
List<Integer> prevRow = result.get(i - 1);
row.add(prevRow.get(j - 1) + prevRow.get(j));
}

}
result.add(row);

}
return result;
}
}

Ответить
@tejajonas
@tejajonas - 23.08.2023 07:57

understood

Ответить
@rahuljmd
@rahuljmd - 22.08.2023 16:25

Understood brother, Thanks for this amazing amazing explanation...

Ответить
@p1xel3434
@p1xel3434 - 19.08.2023 19:00

nCr = nC(n-r) so, we can take i < min(n, n - r) it is more efficient

Ответить
@harshverma9675
@harshverma9675 - 19.08.2023 16:36

Bhaiya, Combination wale question ki bhi list bana do please, Ya phir Combination ke concept ke baare mai ek acchi video bana do.

Ответить

Поздравление с днём пограничника. #shorts Дневник Алексея из Германии
Голубой огонек. Поздравление с днем пограничника (1967) Советское телевидение. ГОСТЕЛЕРАДИОФОНД
С днём пограничника ПОЗДРАВЛЯЙКА Online