Pascal Triangle | Finding nCr in minimal time

Sdílet
Vložit
  • čas přidán 4. 04. 2023
  • Problem Link: bit.ly/3jY4iuF
    Notes/C++/Java/Python codes: takeuforward.org/data-structu...
    We have solved the problem, and we have gone from brute force and ended with the most optimal solution. Every approach's code has been written in the video itself. Also, we have covered the algorithm with intuition.
    Full Course: bit.ly/tufA2ZYt
    You can follow me across social media, all my handles are below:
    Linkedin/Instagram/Telegram: linktr.ee/takeUforward
    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

Komentáře • 247

  • @takeUforward
    @takeUforward  Před 10 měsíci +20

    Please watch our new video on the same topic: czcams.com/video/bR7mQgwQ_o8/video.html

  • @takeUforward
    @takeUforward  Před rokem +134

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

    • @shra1
      @shra1 Před rokem +1

      Did this problem move to easy from hard?

    • @ankushprajapati519
      @ankushprajapati519 Před 11 měsíci +1

      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 Před měsícem +1

      done bhaiya

  • @divyareddy7622
    @divyareddy7622 Před rokem +77

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

  • @naveensaicremsiyadlapalli3769

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

  • @priy9491
    @priy9491 Před měsícem +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 Před 24 dny +2

      that's what I was thinking

    • @Gurunat16
      @Gurunat16 Před 15 dny

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

  • @swacharahman5084
    @swacharahman5084 Před rokem +32

    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.

  • @cinime
    @cinime Před rokem +7

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

  • @p1xel3434
    @p1xel3434 Před 10 měsíci +9

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

    • @chiraggill2940
      @chiraggill2940 Před měsícem

      will not affect complexity though so no need

  • @bilalahmedkhan5876
    @bilalahmedkhan5876 Před rokem

    Loved it, very well explained!

  • @md.ualiurrahmanrahat2400
    @md.ualiurrahmanrahat2400 Před 4 měsíci +2

    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!

  • @chethanprabhu4475
    @chethanprabhu4475 Před rokem +10

    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

  • @infinitecodes
    @infinitecodes Před 9 měsíci +1

    Thank you very much for this amazing course 🎉❤

  • @depthsoffacts3651
    @depthsoffacts3651 Před rokem +2

    🔥🔥 love your teaching 🤗 you are my inspiration

  • @akashkumarmaurya2319
    @akashkumarmaurya2319 Před 10 měsíci +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

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 Před rokem

    Awesome explanation as usual💗

  • @artitech6668
    @artitech6668 Před rokem

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

  • @NikitaSingh-kz2ii
    @NikitaSingh-kz2ii Před rokem +1

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

  • @habeeblaimusa4466
    @habeeblaimusa4466 Před rokem

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

  • @priyotoshsahaThePowerOf23

    Thanks for taking us forward,, Striver❤

  • @poojakumarisingh5506
    @poojakumarisingh5506 Před rokem

    Awesome video. Thankyou striver ❤❤

  • @ashutoshsahu5567
    @ashutoshsahu5567 Před rokem +1

    Frankly speaking I am not able to understand Pascal triangle problem until I watched this video, Earlier I see almost 5-7 videos on CZcams , 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.

  • @bharathis7890
    @bharathis7890 Před rokem

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

  • @ishaanrejra1084
    @ishaanrejra1084 Před rokem

    You are the best !

  • @complexcat6329
    @complexcat6329 Před 8 měsíci

    understood, thank you!

  • @Manishgupta200
    @Manishgupta200 Před rokem

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

  • @rahuljmd
    @rahuljmd Před 10 měsíci

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

  • @heyanikethere
    @heyanikethere Před rokem

    Great work....

  • @venup2813
    @venup2813 Před 5 měsíci +2

    Excellent 👌

  • @NazeerBashaShaik
    @NazeerBashaShaik Před 4 měsíci

    Understood, thank you.

  • @vanamadinarendra2974
    @vanamadinarendra2974 Před rokem

    Keep doing great 👍🎉

  • @yamini436
    @yamini436 Před rokem

    understood :) thankyou striver

  • @rishabhgupta1222
    @rishabhgupta1222 Před 2 měsíci

    Understood very well

  • @inspiringzone12
    @inspiringzone12 Před rokem +1

    Excellent👍👏

  • @Shivi32590
    @Shivi32590 Před měsícem

    understood. Respect!

  • @itsabhinav04
    @itsabhinav04 Před rokem

    Understood, thanks :)

  • @user-dk3pv4zi2s
    @user-dk3pv4zi2s Před měsícem

    superb explanation

  • @hxgaming8886
    @hxgaming8886 Před 5 měsíci

    good video ... understood

  • @ashishpradhan6250
    @ashishpradhan6250 Před měsícem

    understood ..Thanks🙂

  • @YourCodeVerse
    @YourCodeVerse Před 8 měsíci

    Understood✅🔥🔥

  • @nishant4595
    @nishant4595 Před měsícem +1

    understood!!

  • @souvikbiswas292
    @souvikbiswas292 Před 11 měsíci

    You are the GOD of dsa

  • @konankikeerthi
    @konankikeerthi Před měsícem

    Thanks bro. Understood

  • @thebestofyoutube4810
    @thebestofyoutube4810 Před 4 měsíci

    Thanks a lot my ninja.....

  • @desktopgyan9715
    @desktopgyan9715 Před rokem

    Understood❤️

  • @sarthakjain1824
    @sarthakjain1824 Před rokem +2

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

    • @takeUforward
      @takeUforward  Před rokem +24

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

    • @AdityaSingh-in6ce
      @AdityaSingh-in6ce Před 8 měsíci

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

  • @shaktijain8560
    @shaktijain8560 Před 4 měsíci

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

  • @shivamjain1811
    @shivamjain1811 Před rokem +6

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

    • @adirohilla
      @adirohilla Před 9 měsíci +1

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

    • @tarunrajput6865
      @tarunrajput6865 Před měsícem +1

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

  • @Editzx.10
    @Editzx.10 Před měsícem +1

    Understood!

  • @culeforever5408
    @culeforever5408 Před 8 měsíci +1

    understood 😇

  • @Sillysmiles76
    @Sillysmiles76 Před rokem

    understood !

  • @ahmedyasser4928
    @ahmedyasser4928 Před 3 měsíci

    Understood ❤

  • @her_soulmate
    @her_soulmate Před 10 měsíci

    Understood 🎉

  • @abhisheksa6635
    @abhisheksa6635 Před 7 měsíci

    Love it

  • @anitha8562
    @anitha8562 Před rokem +1

    Striver!!Please upload videos on binary search.

  • @sujalsisodiya2091
    @sujalsisodiya2091 Před 11 měsíci

    helpful❤

  • @heyOrca2711
    @heyOrca2711 Před 3 měsíci +1

    Understood! sir

  • @vigneshkumarganesan1529
    @vigneshkumarganesan1529 Před 6 měsíci +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?

  • @arnavsaha3631
    @arnavsaha3631 Před rokem

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

  • @harshitkhurana766
    @harshitkhurana766 Před rokem +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

  • @jhanavikumari274
    @jhanavikumari274 Před 2 měsíci

    you sorcerer :)

  • @ARYANGUPTARA
    @ARYANGUPTARA Před rokem +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)

  • @AniketKumar-hf2bo
    @AniketKumar-hf2bo Před 5 měsíci

    understood 👌👌👌👌❤❤❤❤

  • @shaurya2608
    @shaurya2608 Před rokem

    Understood

  • @prabhatkumarsingh3073
    @prabhatkumarsingh3073 Před 8 měsíci

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

  • @soumiyamuthuraj3516
    @soumiyamuthuraj3516 Před 26 dny

    Awesome

  • @johndurai2226
    @johndurai2226 Před rokem

    understood bro

  • @suryasaimaheswar8636
    @suryasaimaheswar8636 Před 20 dny

    understood :)

  • @deokumarjnu
    @deokumarjnu Před 5 měsíci

    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.

  • @ashwinselvarangan8482
    @ashwinselvarangan8482 Před rokem +2

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

  • @AbjSir
    @AbjSir Před 9 měsíci

    understood

  • @suyashshinde2971
    @suyashshinde2971 Před rokem +2

    SDE Sheet: Day 1 Problem 2 Done!

  • @yasaswiv2030
    @yasaswiv2030 Před 6 měsíci

    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

  • @user-uv5or5bm2c
    @user-uv5or5bm2c Před 4 měsíci

    Understood.

  • @akashverma5756
    @akashverma5756 Před rokem

    We personally call it Parallel computing or Stacking method.

  • @jatinsareen7771
    @jatinsareen7771 Před rokem +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.

  • @arnavjain6038
    @arnavjain6038 Před 5 dny

    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.

  • @psrs985
    @psrs985 Před 3 měsíci

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

  • @ayushuniyal2586
    @ayushuniyal2586 Před rokem

    please do reply bhaiya,in your sde sheet you have not given explaination of heaps part :(,please cover this urgent solution of heapss problems in your sde sheet

  • @yashisharma3621
    @yashisharma3621 Před 4 měsíci

    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 Před rokem +1

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

  • @sarangkumarsingh7901
    @sarangkumarsingh7901 Před 3 měsíci

    Understood..........

  • @princeeshah5229
    @princeeshah5229 Před 10 měsíci

    Understood❤❤❤❤❤

  • @akhilmittal2762
    @akhilmittal2762 Před 6 měsíci

    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

  • @BB-rh7gl
    @BB-rh7gl Před 5 dny

    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.

  • @alphadrones23
    @alphadrones23 Před rokem +1

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

  • @reddygopichand2002
    @reddygopichand2002 Před 8 měsíci

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

  • @rohitprasad2147
    @rohitprasad2147 Před rokem +1

    can anyone give me the java solution because we implement similar logic in java they are showing me the:- n compatible types: List> cannot be converted to int[][]
    int [][]ans = Solution.pascalTriangle(n); so plz help me

  • @rishabhupadhyay8165
    @rishabhupadhyay8165 Před 9 měsíci

    Thanks

  • @harshverma9675
    @harshverma9675 Před 10 měsíci

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

  • @priyaraj1703
    @priyaraj1703 Před rokem

    🔥🔥

  • @prajwalnakure
    @prajwalnakure Před 3 měsíci

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

  • @RohitRohit-zp3zs
    @RohitRohit-zp3zs Před 4 dny +1

    10 rs ki pepsi striver bhai ki explaination sexyyy!!!

  • @Xp-Sam
    @Xp-Sam Před rokem +1

    Which whiteboard app striver is using for explaining ?

  • @user-nk1mb5fy7j
    @user-nk1mb5fy7j Před rokem

    Bhaiya gfg mein yeh 2nd method 50th test case mein error de raha hain ,long long bhi use kiya fir bhi nahi chal raha

  • @Shri_2002
    @Shri_2002 Před rokem

    Waiting for string series

  • @iamvtyagii9540
    @iamvtyagii9540 Před měsícem

    striver ❤

  • @deepakagrawal7687
    @deepakagrawal7687 Před rokem

    can't we do like caclulate numerator (10*9*8) and denominator(3*2*1) and then divide. 720/6 = 120

  • @senseiAree
    @senseiAree Před 9 měsíci

    Understood

  • @user-kg1tt8pw4t
    @user-kg1tt8pw4t Před 4 měsíci

    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 Před 4 měsíci

      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?

  • @kartikkk4583
    @kartikkk4583 Před rokem

    respect++