Pascal Triangle | Finding nCr in minimal time

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ต.ค. 2024

ความคิดเห็น • 311

  • @takeUforward
    @takeUforward  ปีที่แล้ว +31

    Please watch our new video on the same topic: th-cam.com/video/bR7mQgwQ_o8/w-d-xo.html

    • @arpitbhavsar6020
      @arpitbhavsar6020 4 หลายเดือนก่อน +4

      Recursion without a base case 😁😁

    • @KurumiddeKezia
      @KurumiddeKezia 3 หลายเดือนก่อน

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

    • @the_avii_7
      @the_avii_7 หลายเดือนก่อน

      @@arpitbhavsar6020 🤣🤣

  • @takeUforward
    @takeUforward  ปีที่แล้ว +181

    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

  • @divyareddy7622
    @divyareddy7622 ปีที่แล้ว +112

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

  • @swacharahman5084
    @swacharahman5084 ปีที่แล้ว +42

    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.

  • @p1xel3434
    @p1xel3434 ปีที่แล้ว +13

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

    • @chiraggill2940
      @chiraggill2940 5 หลายเดือนก่อน +1

      will not affect complexity though so no need

  • @md.ualiurrahmanrahat2400
    @md.ualiurrahmanrahat2400 8 หลายเดือนก่อน +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!

  • @naveensaicremsiyadlapalli3769
    @naveensaicremsiyadlapalli3769 ปีที่แล้ว +66

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

  • @RaunitJaiswal-s9v
    @RaunitJaiswal-s9v หลายเดือนก่อน

    - [00:02](th-cam.com/video/bR7mQgwQ_o8/w-d-xo.html) 🧠 Overview of the DS Algo course and problem statement of Pascal's triangle
    - The course is extensive and covers over 400 problems in DS algo
    - Introduction to Pascal's triangle and its structure
    - Explanation of three types of problems related to Pascal's triangle
    - [03:53](th-cam.com/video/bR7mQgwQ_o8/w-d-xo.html) 🧮 Calculating nCr using brute force method
    - Discussing the traditional brute force method to calculate nCr
    - Explaining the formula for nCr and line-by-line code implementation for nCr calculation
    - Detailed explanation of time complexity considerations and space complexity
    - [10:55](th-cam.com/video/bR7mQgwQ_o8/w-d-xo.html) 🖨 Optimizing the calculation of nth row of Pascal's triangle
    - Introducing the optimization to calculate the nth row more efficiently
    - Deriving a formula based on observations to calculate elements of the nth row
    - Implementing the optimized code for generating and printing the nth row
    - [19:30](th-cam.com/video/bR7mQgwQ_o8/w-d-xo.html) 🪙 Generating the entire Pascal's triangle efficiently
    - Explaining a naive brute force approach to generate the entire Pascal's triangle
    - Describing a more optimized method using the second type of problem solution
    - Discussing the time complexity reduction strategy for generating the complete Pascal's triangle with improved efficiency
    - [22:02](th-cam.com/video/bR7mQgwQ_o8/w-d-xo.html) 🧮 Solution complexity analysis
    - Optimal time complexity for type 3 problem is O(n^2)
    - Generating each row has a time complexity of O(n)
    - Using long long data type is recommended due to potential large number calculations
    - [24:24](th-cam.com/video/bR7mQgwQ_o8/w-d-xo.html) 📝 Coding the solution
    - Write a function to generate a row based on the row number
    - Use the function to generate the entire triangle structure
    - Code quality is important in interviews, focus on readability and structure
    - [26:04](th-cam.com/video/bR7mQgwQ_o8/w-d-xo.html) 📚 Final notes and channel engagement
    - Encouragement to like the video to support content creation
    - Importance of subscribing for more content
    - Follow links in the description for further engagement on social media platforms

  • @akashkumarmaurya2319
    @akashkumarmaurya2319 ปีที่แล้ว +2

    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

  • @mirishfaqhussain6168
    @mirishfaqhussain6168 หลายเดือนก่อน +1

    His involvement while he delivers the lecture is motivational ❤

  • @priy9491
    @priy9491 4 หลายเดือนก่อน +9

    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 4 หลายเดือนก่อน +2

      that's what I was thinking

    • @Gurunat16
      @Gurunat16 4 หลายเดือนก่อน

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

    • @priyankasoni5537
      @priyankasoni5537 2 หลายเดือนก่อน

      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 หลายเดือนก่อน

      @@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 หลายเดือนก่อน

      @@AnkitKumar-su1yi thank u understood

  • @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

  • @sarthakjain1824
    @sarthakjain1824 ปีที่แล้ว +5

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

    • @takeUforward
      @takeUforward  ปีที่แล้ว +25

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

    • @AdityaSingh-in6ce
      @AdityaSingh-in6ce ปีที่แล้ว

      there is no good playlist for string on TH-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 TH-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.

  • @amansayyad7286
    @amansayyad7286 3 หลายเดือนก่อน

    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!!

  • @NikitaSingh-kz2ii
    @NikitaSingh-kz2ii ปีที่แล้ว +1

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

  • @deokumarjnu
    @deokumarjnu 8 หลายเดือนก่อน +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.

  • @jatinsareen7771
    @jatinsareen7771 ปีที่แล้ว +19

    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.

  • @infinitecodes
    @infinitecodes ปีที่แล้ว +1

    Thank you very much for this amazing course 🎉❤

  • @priyotoshsahaThePowerOf23
    @priyotoshsahaThePowerOf23 ปีที่แล้ว +3

    Thanks for taking us forward,, Striver❤

  • @depthsoffacts3651
    @depthsoffacts3651 ปีที่แล้ว +2

    🔥🔥 love your teaching 🤗 you are my inspiration

  • @venup2813
    @venup2813 9 หลายเดือนก่อน +2

    Excellent 👌

  • @habeeblaimusa4466
    @habeeblaimusa4466 ปีที่แล้ว +1

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

  • @Manishgupta200
    @Manishgupta200 ปีที่แล้ว

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

  • @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

  • @shaktijain8560
    @shaktijain8560 8 หลายเดือนก่อน

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

  • @suyashshinde2971
    @suyashshinde2971 ปีที่แล้ว +3

    SDE Sheet: Day 1 Problem 2 Done!

  • @sainallajarla7022
    @sainallajarla7022 หลายเดือนก่อน

    UNDERSTOODDDD STRIVER !!!

  • @sourabhsoni5065
    @sourabhsoni5065 2 หลายเดือนก่อน

    Very Nice Explanation

  • @artitech6668
    @artitech6668 ปีที่แล้ว

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

  • @gourishetti-y6c
    @gourishetti-y6c ปีที่แล้ว

    Loved it, very well explained!

  • @akshatmalviya8563
    @akshatmalviya8563 2 หลายเดือนก่อน +1

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

  • @souvikbiswas292
    @souvikbiswas292 ปีที่แล้ว

    You are the GOD of dsa

  • @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 🫶

  • @bharathis7890
    @bharathis7890 ปีที่แล้ว

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

  • @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)

  • @anitha8562
    @anitha8562 ปีที่แล้ว +1

    Striver!!Please upload videos on binary search.

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 14 วันที่ผ่านมา

    NICE SUPER EXCELLENT MOTIVATED

  • @rahuljmd
    @rahuljmd ปีที่แล้ว

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

  • @AjeyaKumaraK
    @AjeyaKumaraK 4 หลายเดือนก่อน

    superb explanation

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 ปีที่แล้ว

    Awesome explanation as usual💗

  • @arnavjain6038
    @arnavjain6038 3 หลายเดือนก่อน

    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.

  • @torishi82
    @torishi82 3 หลายเดือนก่อน

    Samaj aa gaya!!

  • @AshutoshVerma-d4z
    @AshutoshVerma-d4z 8 หลายเดือนก่อน

    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 7 หลายเดือนก่อน

      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?

  • @culeforever5408
    @culeforever5408 ปีที่แล้ว +1

    understood 😇

  • @ishaanrejra1084
    @ishaanrejra1084 ปีที่แล้ว

    You are the best !

  • @inspiringzone12
    @inspiringzone12 ปีที่แล้ว +1

    Excellent👍👏

  • @shrutisrivastava7174
    @shrutisrivastava7174 11 หลายเดือนก่อน +2

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

  • @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 4 หลายเดือนก่อน +1

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

  • @poojakumarisingh5506
    @poojakumarisingh5506 ปีที่แล้ว

    Awesome video. Thankyou striver ❤❤

  • @rishabhgupta1222
    @rishabhgupta1222 6 หลายเดือนก่อน

    Understood very well

  • @complexcat6329
    @complexcat6329 ปีที่แล้ว

    understood, thank you!

  • @shanks5719
    @shanks5719 24 วันที่ผ่านมา

    Understood, sir.

  • @Shivi32590
    @Shivi32590 4 หลายเดือนก่อน

    understood. Respect!

  • @heyanikethere
    @heyanikethere ปีที่แล้ว

    Great work....

  • @psrs985
    @psrs985 7 หลายเดือนก่อน

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

  • @prajwalnakure
    @prajwalnakure 7 หลายเดือนก่อน

    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 TH-camr encourages viewers to subscribe and engage with their content.

  • @hetpatel7399
    @hetpatel7399 ปีที่แล้ว +3

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

  • @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 8 หลายเดือนก่อน

    Understood, thank you.

  • @heyOrca2711
    @heyOrca2711 7 หลายเดือนก่อน +1

    Understood! sir

  • @kj5215
    @kj5215 ปีที่แล้ว

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

  • @vanamadinarendra2974
    @vanamadinarendra2974 ปีที่แล้ว

    Keep doing great 👍🎉

  • @nishant4595
    @nishant4595 4 หลายเดือนก่อน +1

    understood!!

  • @ashishpradhan6250
    @ashishpradhan6250 5 หลายเดือนก่อน

    understood ..Thanks🙂

  • @trsk
    @trsk 3 หลายเดือนก่อน

    thank you Anna

  • @yamini436
    @yamini436 ปีที่แล้ว

    understood :) thankyou striver

  • @codeman3828
    @codeman3828 2 หลายเดือนก่อน

    Wonderful

  • @konankikeerthi
    @konankikeerthi 4 หลายเดือนก่อน

    Thanks bro. Understood

  • @hxgaming8886
    @hxgaming8886 8 หลายเดือนก่อน

    good video ... understood

  • @SumitMishra-rb8zo
    @SumitMishra-rb8zo หลายเดือนก่อน

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

  • @reddygopichand2002
    @reddygopichand2002 11 หลายเดือนก่อน

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

  • @thebestofyoutube4810
    @thebestofyoutube4810 7 หลายเดือนก่อน

    Thanks a lot my ninja.....

  • @sumitworld918
    @sumitworld918 11 หลายเดือนก่อน

    Understood ❤

  • @shambhaviaggarwal9977
    @shambhaviaggarwal9977 25 วันที่ผ่านมา

    understood!

  • @Editzx.10
    @Editzx.10 4 หลายเดือนก่อน +1

    Understood!

  • @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

  • @ChiragDhamija-b4n
    @ChiragDhamija-b4n 4 หลายเดือนก่อน

    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

  • @YourCodeVerse
    @YourCodeVerse ปีที่แล้ว

    Understood✅🔥🔥

  • @vigneshkumarganesan1529
    @vigneshkumarganesan1529 9 หลายเดือนก่อน +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?

  • @anshulrai6058
    @anshulrai6058 16 วันที่ผ่านมา

    understood👍

  • @AlokSingh-jw8fr
    @AlokSingh-jw8fr ปีที่แล้ว +1

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

  • @gautamsaxena4647
    @gautamsaxena4647 หลายเดือนก่อน

    understood bhaiya

  • @meghnakhaitan2495
    @meghnakhaitan2495 ปีที่แล้ว +1

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

  • @RajNamdev_19
    @RajNamdev_19 4 หลายเดือนก่อน +1

    Understood

  • @AshishSahu-ef9rl
    @AshishSahu-ef9rl 2 หลายเดือนก่อน

    Maja aagaya 😊

  • @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

  • @itsabhinav04
    @itsabhinav04 ปีที่แล้ว

    Understood, thanks :)

  • @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?

  • @akashverma5756
    @akashverma5756 ปีที่แล้ว

    We personally call it Parallel computing or Stacking method.

  • @yashisharma3621
    @yashisharma3621 7 หลายเดือนก่อน

    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?

  • @Shakti_singh96
    @Shakti_singh96 2 หลายเดือนก่อน

    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 TH-camr encourages viewers to subscribe and engage with their content.
    Crafted by jai rajputana

  • @her_soulmate
    @her_soulmate ปีที่แล้ว

    Understood 🎉

  • @callmesumant
    @callmesumant หลายเดือนก่อน

    understood.

  • @arnavsaha3631
    @arnavsaha3631 ปีที่แล้ว

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

  • @DeadPoolx1712
    @DeadPoolx1712 2 หลายเดือนก่อน

    UNDERSTOOD;

  • @sujalsisodiya2091
    @sujalsisodiya2091 ปีที่แล้ว

    helpful❤

  • @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) )

  • @BB-rh7gl
    @BB-rh7gl 3 หลายเดือนก่อน

    Can someone please explain how you intuitively figure out that a formula like the binomial coefficient needs to be used in a problem like this? I can't see how it would occur to me unless I've memorized it.