Pascal Triangle | Finding nCr in minimal time

Поділитися
Вставка
  • Опубліковано 26 лис 2024

КОМЕНТАРІ • 320

  • @takeUforward
    @takeUforward  Рік тому +33

    Please watch our new video on the same topic: ua-cam.com/video/bR7mQgwQ_o8/v-deo.html

    • @arpitbhavsar6020
      @arpitbhavsar6020 5 місяців тому +4

      Recursion without a base case 😁😁

    • @KurumiddeKezia
      @KurumiddeKezia 4 місяці тому

      Bro one dout my code is executed in codestudio but not executed in leetcode y😢

    • @the_avii_7
      @the_avii_7 2 місяці тому

      @@arpitbhavsar6020 🤣🤣

  • @takeUforward
    @takeUforward  Рік тому +186

    Please do like the video, it won't cost you anything, but it will highly motivate me :)

    • @shra1
      @shra1 Рік тому +1

      Did this problem move to easy from hard?

    • @ankushprajapati519
      @ankushprajapati519 Рік тому +2

      Ofcourse we do......
      But not only for motivation,but also for your efforts.......😊
      Such type of free content is very helpful for those persons who are not capable to buy an expensive course......👍✨

    • @newsbuster2194
      @newsbuster2194 5 місяців тому +1

      done bhaiya

  • @naveensaicremsiyadlapalli3769
    @naveensaicremsiyadlapalli3769 Рік тому +69

    #include
    using namespace std;
    class PascalsTriangle{
    private:
    int Ncr(int n,int r)
    {
    int ans=1;
    for(int i=1;i

  • @divyareddy7622
    @divyareddy7622 Рік тому +120

    your videos actually got me out of depression and gave me aa hope at becoming better at DSA!!!!

  • @swacharahman5084
    @swacharahman5084 Рік тому +45

    I always amazed the level of intelligence you have brother, Thank you for this playlist, Trust me your playlist is making thousands/millions of students better coder.

  • @md.ualiurrahmanrahat2400
    @md.ualiurrahmanrahat2400 9 місяців тому +3

    used to solve this problem by myself but the solution was brute force method. Never have I ever thought this problem can be solved by such observation. Hats off to the effort Striver puts in his video. Incredible!

  • @p1xel3434
    @p1xel3434 Рік тому +14

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

    • @chiraggill2940
      @chiraggill2940 6 місяців тому +2

      will not affect complexity though so no need

  • @akashkumarmaurya2319
    @akashkumarmaurya2319 Рік тому +3

    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

  • @sarthakjain1824
    @sarthakjain1824 Рік тому +8

    450 questions will need many months of continuous hard work. Hats off bhaiya

    • @takeUforward
      @takeUforward  Рік тому +26

      We have already covered > 60%, trees : 56, graphs: 56 dp: 56 ;)

    • @AdityaSingh-in6ce
      @AdityaSingh-in6ce Рік тому

      there is no good playlist for string on UA-cam only one or two videos and its and important topic please start with string@@takeUforward

  • @ashutoshsahu5567
    @ashutoshsahu5567 Рік тому +2

    Frankly speaking I am not able to understand Pascal triangle problem until I watched this video, Earlier I see almost 5-7 videos on UA-cam , from those videos I Get what is the pascal triangle, but didn't able to solve the problem. After watching this video, I have confidence to solve any problem based on pascal triangle.

  • @priy9491
    @priy9491 5 місяців тому +10

    We can reduce the time complexity to (n^2/2) by running the inner loop only for row/2 times and assigning values symmetrically because the pascals triangle is symmetric.
    Thank you for the videos!

    • @RajNamdev_19
      @RajNamdev_19 5 місяців тому +2

      that's what I was thinking

    • @Gurunat16
      @Gurunat16 5 місяців тому

      To add symmetry to the result, you need to run a loop right? Or is there any other ways?

    • @priyankasoni5537
      @priyankasoni5537 3 місяці тому

      Can you please explain Space complexity of both the approaches of variation 3? Like how come it is O(1)(Written in the sheets notes and also strivers mentioned in the video

    • @AnkitKumar-su1yi
      @AnkitKumar-su1yi 2 місяці тому

      @@priyankasoni5537 yes its O(1) because we are not using any extra space like we are asked to print the pascals triangle so we are just using a list to store and print it that's it

    • @priyankasoni5537
      @priyankasoni5537 2 місяці тому

      @@AnkitKumar-su1yi thank u understood

  • @mirishfaqhussain6168
    @mirishfaqhussain6168 2 місяці тому +1

    His involvement while he delivers the lecture is motivational ❤

  • @chethanprabhu4475
    @chethanprabhu4475 Рік тому +11

    Finally I was able to solve a problem before looking at your solution. That too hard one 😎 All thanks to your foundational videos on Arrays ♥
    Watched the video anyways. Just to look at your approach

  • @NikitaSingh-kz2ii
    @NikitaSingh-kz2ii Рік тому +1

    APPROACH TO THIS PROBLEM IS SUPER SE V BHT BHT BHT ZYADA UPAR🔥🔥🔥🔥🔥🔥🔥🔥🔥

  • @parasarora5869
    @parasarora5869 2 дні тому

    That was fabulous. I didn't know about nCr unfortunately, but I learned it separately from other videos. Thanks for the great video. ❤

  • @amansayyad7286
    @amansayyad7286 4 місяці тому

    i think best teacher present is this man. Please try to motivate him and support him. Love you bro

  • @cinime
    @cinime Рік тому +7

    Understood! Super awesome explanation as always, thank you very very much for your effort!!

  • @ARYANGUPTARA
    @ARYANGUPTARA Рік тому +1

    Python code for 1st variant
    def pascal(n,r):
    res = 1
    for i in range(r):
    res = res * (n-i)
    res = res/(i+1)
    print(res)
    n = int(input("Value of N"))
    r = int(input("Value of R"))
    pascal(n-1,r-1)

  • @AS-gf3ci
    @AS-gf3ci Рік тому

    Q.2 Code in C++
    #include
    using namespace std;
    void printRow(int n) { // T.C --> O(n) S.C --> O(1)
    int ans = 1;
    cout

  • @souvikbiswas292
    @souvikbiswas292 Рік тому

    You are the GOD of dsa

  • @arnavjain6038
    @arnavjain6038 4 місяці тому

    class Solution(object):
    def pascal(self, numRows):
    pt=[[1]]*(numRows)
    pt[0]=[1]
    for i in range(1,numRows):
    pt[i]=[1]*(i+1)
    for j in range(1,i):
    pt[i][j] = pt[i-1][j-1]+pt[i-1][j]
    return pt
    for generating entire pascal's triangle.

  • @deokumarjnu
    @deokumarjnu 9 місяців тому +2

    Thanks Striver, my code is not passing because of spacing issue in between digits😌 we can do in more way, pascle is nothing but power of 11, so if it's asking for N, then just run a loop from 1 to N and calculate the power(11, i), push into the vector if spacing is not considered. Stuck with spacing.

  • @prajwalnakure
    @prajwalnakure 8 місяців тому

    00:04 Pascal's Triangle - A pattern of numbers where each number is the sum of the two directly above it.
    02:05 Finding element at a specific row and column in Pascal Triangle.
    06:48 Shortcut for finding nCr in minimal time: multiply numbers from n to n-r+1.
    09:11 The numerator in nCr calculation keeps getting multiplied and then divided with the value of i+1.
    13:39 Pascal Triangle formula is used to find nCr in minimal time.
    15:59 Pascal Triangle for finding nCr
    20:22 Generate Pascal Triangle row in minimal time
    22:16 Optimal solution for finding nCr in minimal time
    26:16 The UA-camr encourages viewers to subscribe and engage with their content.

  • @prabhatkumarsingh3073
    @prabhatkumarsingh3073 Рік тому

    3:40 4th type question can be asked is sum of nth row
    ans :simple left lift 1 by (n-1) that is 1

  • @priyotoshsahaThePowerOf23
    @priyotoshsahaThePowerOf23 Рік тому +3

    Thanks for taking us forward,, Striver❤

  • @infinitecodes
    @infinitecodes Рік тому +1

    Thank you very much for this amazing course 🎉❤

  • @depthsoffacts3651
    @depthsoffacts3651 Рік тому +2

    🔥🔥 love your teaching 🤗 you are my inspiration

  • @aakarshshukla8364
    @aakarshshukla8364 26 днів тому +1

    congrats striver for 700k and happy Diwali🎆🎆🎇🎇🧨🧨

  • @suyashshinde2971
    @suyashshinde2971 Рік тому +3

    SDE Sheet: Day 1 Problem 2 Done!

  • @AshutoshVerma-d4z
    @AshutoshVerma-d4z 9 місяців тому +2

    instead, for the first problem, the loop should run for min(r, n-r) and not 'r' because if it is 10C7, r is bigger than n-r

    • @harshsinha7642
      @harshsinha7642 8 місяців тому

      I tried solving ncr problem with this approach but still test cases are failing for ex 69c43
      You can search ncr problem gfg ... Can you try solving with first approach along with min(n-r, r) modification and let me know?

  • @habeeblaimusa4466
    @habeeblaimusa4466 Рік тому +1

    Your explanation is superb ❤️❤️..
    Ride on Striver.

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Рік тому +2

    Public class{
    Public static int[][]pascal Triangle(int N)
    int[][]triangle =new int(N)(N);
    for(inti=0;i

  • @Manishgupta200
    @Manishgupta200 Рік тому

    It's a very tricky problem based of math nCr.. approach by you is really good

  • @shaktijain8560
    @shaktijain8560 9 місяців тому

    Each row is binomial expansion coefficient for certain power. We can directly use combination formula to get it .

  • @venup2813
    @venup2813 10 місяців тому +2

    Excellent 👌

  • @artitech6668
    @artitech6668 Рік тому

    Amazing explanation. thanks a ton. Working harder to make u proud.

  • @Mohit-s9c2v
    @Mohit-s9c2v 8 днів тому

    understood, Thankyou Striver

  • @rahuljmd
    @rahuljmd Рік тому

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

  • @bilalahmedkhan5876
    @bilalahmedkhan5876 Рік тому

    Loved it, very well explained!

  • @dishaparwani6711
    @dishaparwani6711 Рік тому

    class Solution{
    public:
    vector generateRow(int row) {
    long long ans = 1;
    vector 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 nthRowOfPascalTriangle(int n) {
    // code here
    vector ans;
    //store the entire pascal's triangle:
    for (int row = 1; row

  • @bharathis7890
    @bharathis7890 Рік тому

    verrry good explanation and even the methods of solving the given problem😇

  • @Shakti_singh96
    @Shakti_singh96 3 місяці тому

    00:04 Pascal's Triangle - A pattern of numbers where each number is the sum of the two directly above it.
    02:05 Finding element at a specific row and column in Pascal Triangle.
    06:48 Shortcut for finding nCr in minimal time: multiply numbers from n to n-r+1.
    09:11 The numerator in nCr calculation keeps getting multiplied and then divided with the value of i+1.
    13:39 Pascal Triangle formula is used to find nCr in minimal time.
    15:59 Pascal Triangle for finding nCr
    20:22 Generate Pascal Triangle row in minimal time
    22:16 Optimal solution for finding nCr in minimal time
    26:16 The UA-camr encourages viewers to subscribe and engage with their content.
    Crafted by jai rajputana

  • @sainallajarla7022
    @sainallajarla7022 2 місяці тому

    UNDERSTOODDDD STRIVER !!!

  • @ChiragDhamija-b4n
    @ChiragDhamija-b4n 5 місяців тому

    another solution for generating pascal triangle , its Time Complexity is O(n^2/2) and space complexity to O(n^2/2)
    class Solution {
    public:
    vector generate(int numRows)
    {
    vector ans(numRows);
    for(int i=0;i

  • @sourabhsoni5065
    @sourabhsoni5065 3 місяці тому

    Very Nice Explanation

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 Рік тому

    Awesome explanation as usual💗

  • @kj5215
    @kj5215 Рік тому

    1st -> 3:51
    2nd -> 10:55
    3rd -> 19:21

  • @AjeyaKumaraK
    @AjeyaKumaraK 5 місяців тому

    superb explanation

  • @poojakumarisingh5506
    @poojakumarisingh5506 Рік тому

    Awesome video. Thankyou striver ❤❤

  • @akshatmalviya8563
    @akshatmalviya8563 3 місяці тому +1

    I did the last part with dp. Complexity was O(n^2)

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 Місяць тому

    NICE SUPER EXCELLENT MOTIVATED

  • @jatinsareen7771
    @jatinsareen7771 Рік тому +20

    Hey striver, I was having a doubt that will you cover up some competitive programming concepts in this course or not?? Because covering all cp topics will make this course legendary and no one will be able to surpass this level in generations.

  • @introvert9112k
    @introvert9112k Рік тому +1

    Just a small improvement for the nCr calculation.
    int findNumber(int n,int r)
    {
    long long res = 1;
    for(int i = n; i > max(r,n-r); --i)
    {
    res*=i;
    res/=(n-i+1);
    }
    return res;
    }
    Time Complexity : O( min(r, n-r) )

  • @shivamjain1811
    @shivamjain1811 Рік тому +7

    whats the intiution behind (n-1)C(r-1) ? can someone plz tell

    • @adirohilla
      @adirohilla Рік тому +2

      I am also looking for its intuition, thanks for raising this , but nobody has still answered on it yet

    • @tarunrajput6865
      @tarunrajput6865 5 місяців тому +1

      12:43 yaha se dekh Bhai agr phir bhi na smjh aye TB btayio

  • @shrutisrivastava7174
    @shrutisrivastava7174 Рік тому +2

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

  • @frustrated_newbiecoder1674
    @frustrated_newbiecoder1674 Рік тому +2

    Hey guys, I'm not understanding why we need to solve this using this formula. It's taking same amount of time and complexity that we needed to solve the problem using loops

    • @abhaykumarprasad4131
      @abhaykumarprasad4131 Рік тому

      The number wont fit in any integer value it will overflow ... try solving thee question in gfg you will see that the results are in -ve

  • @ishaanrejra1084
    @ishaanrejra1084 Рік тому

    You are the best !

  • @hetpatel7399
    @hetpatel7399 Рік тому +3

    Aap 3rd year me the tab aap kitane hours Coding karate the??

  • @SumitMishra-rb8zo
    @SumitMishra-rb8zo 2 місяці тому

    For Part 1- 3:51 to 10:52, part 2- 10:56 to 19:14

  • @kabilm8040
    @kabilm8040 3 місяці тому

    TRIED MYSELF
    class Solution {
    public:
    vector generate(int numRows) {
    vector ans(numRows);
    for(int i=0;i

  • @reddygopichand2002
    @reddygopichand2002 Рік тому

    We can use ncr=nc(n-r) when r>n/2 10:44

  • @abusufyanmalik
    @abusufyanmalik Рік тому

    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

  • @mehulthuletiya497
    @mehulthuletiya497 Рік тому +11

    Timestamps
    00:51 What do you mean by Pascal's Triangle?
    02:27 3 Types of problems that might be asked to you
    03:52 1st Type Problem Statement
    06:56 Formula shortcut
    07:49 Code
    09:46 Complexity
    10:31 recap
    10:54 2nd Type Problem Statement
    11:38 Brute force
    12:18 Complexity
    12:37 Optimal solution & Deep dive into formula and observation
    15:11 Minor changes and formula
    17:27 Pseudocode
    19:06 Complexity
    19:21 3rd Type Problem Statement
    20:00 Brute force
    20:07 Pseudocode
    21:17 Complexity
    21:50 Optimal Solution
    22:19 Code
    25:16 Interview Tip : Code Quality

    • @takeUforward
      @takeUforward  Рік тому +11

      Just a suggestion, don’t add ‘-‘ in timestamps, its
      00:05 Intro
      Just a space :) it becomes easier for me to copy paste.
      Thank you for always adding it up 🫶

  • @vanamadinarendra2974
    @vanamadinarendra2974 Рік тому

    Keep doing great 👍🎉

  • @torishi82
    @torishi82 4 місяці тому

    Samaj aa gaya!!

  • @arnavsaha3631
    @arnavsaha3631 Рік тому

    This is great...I hope you earn enough from all this 😊

  • @rishabhgupta1222
    @rishabhgupta1222 7 місяців тому

    Understood very well

  • @psrs985
    @psrs985 8 місяців тому

    Or you could use the previously stored values to generate the lower rows which will take O(n*n) TC

  • @anitha8562
    @anitha8562 Рік тому +1

    Striver!!Please upload videos on binary search.

  • @ashwinselvarangan8482
    @ashwinselvarangan8482 Рік тому +2

    Hi, Did anyone here faced probelm in Test Case 50 of Gfg. If yes, then can you please expalin how did you tackle?

  • @heyanikethere
    @heyanikethere Рік тому

    Great work....

  • @Shivi32590
    @Shivi32590 5 місяців тому

    understood. Respect!

  • @culeforever5408
    @culeforever5408 Рік тому +1

    understood 😇

  • @complexcat6329
    @complexcat6329 Рік тому

    understood, thank you!

  • @nitinchandrasahu1774
    @nitinchandrasahu1774 8 місяців тому +1

    Try This. 😁😁
    vector generate(int numRows) {
    vector ans;
    for(int i = 0; i

  • @yamini436
    @yamini436 Рік тому

    understood :) thankyou striver

  • @jineshnadar6409
    @jineshnadar6409 Рік тому

    Printing Pascal triangle using DP
    vector generate(int numRows) {
    vectorfirstRow { 1 };
    vector ans;
    ans.push_back( firstRow );
    for( int row = 2 ; row

  • @inspiringzone12
    @inspiringzone12 Рік тому +1

    Excellent👍👏

  • @AlokSingh-jw8fr
    @AlokSingh-jw8fr Рік тому +1

    int mod = 1000000007;
    int nCr(int n, int r){
    if(n

  • @AshishSahu-ef9rl
    @AshishSahu-ef9rl 3 місяці тому

    Maja aagaya 😊

  • @vigneshkumarganesan1529
    @vigneshkumarganesan1529 10 місяців тому +1

    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?

  • @shanks5719
    @shanks5719 Місяць тому

    Understood, sir.

  • @ashishpradhan6250
    @ashishpradhan6250 6 місяців тому

    understood ..Thanks🙂

  • @YourCodeVerse
    @YourCodeVerse Рік тому

    Understood✅🔥🔥

  • @harshverma9675
    @harshverma9675 Рік тому

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

  • @NazeerBashaShaik
    @NazeerBashaShaik 9 місяців тому

    Understood, thank you.

  • @hxgaming8886
    @hxgaming8886 9 місяців тому

    good video ... understood

  • @heyOrca2711
    @heyOrca2711 8 місяців тому +1

    Understood! sir

  • @akashverma5756
    @akashverma5756 Рік тому

    We personally call it Parallel computing or Stacking method.

  • @vivekreddymynampati6996
    @vivekreddymynampati6996 Рік тому

    vector pascalTriangle(int N) {
    int i, j, res;
    vector ans;
    vector temp;
    for(i=0;i

  • @harshitkhurana766
    @harshitkhurana766 Рік тому +1

    @striver bhaiya could u please make a video on what are sample input output test cases constraints and how to code on online compilers on coding platforms as i am beginner and i am facing difficulty in understanding these

  • @vamsikrishnagannamaneni912
    @vamsikrishnagannamaneni912 2 дні тому

    7:22? I didnot understand part? 10/3 will give me nothing? what does that mean ? it will give 3.333 or 3 if rounded right?

  • @yasaswiv2030
    @yasaswiv2030 11 місяців тому

    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

  • @thebestofyoutube4810
    @thebestofyoutube4810 8 місяців тому

    Thanks a lot my ninja.....

  • @konankikeerthi
    @konankikeerthi 5 місяців тому

    Thanks bro. Understood

  • @nishant4595
    @nishant4595 5 місяців тому +1

    understood!!

  • @alphadrones23
    @alphadrones23 Рік тому +1

    I think to print n rows for pascal triangle would fail for large test cases even if we take MOD of 1e9 + 7

  • @her_soulmate
    @her_soulmate Рік тому

    Understood 🎉

  • @yashisharma3621
    @yashisharma3621 8 місяців тому

    Need some advice! I have been doing DSA consistently for the last 1 month but I wasn’t able to come up with an efficient solution for this problem by myself. I don’t know if I am doing something wrong. Is this actually kind of advanced or I just need more practice?

  • @meghnakhaitan2495
    @meghnakhaitan2495 Рік тому +1

    Can you pls pls plsssss do strings before binary search next plsss🙏 ?