3179. Find the N-th Value After K Seconds | Pascal's Triangle | DP | Bottom Up Optimised DP

Поделиться
HTML-код
  • Опубликовано: 30 сен 2024
  • In this video, I'll talk about how to solve Leetcode 3179. Find the N-th Value After K Seconds | Pascal's Triangle | DP | Bottom Up Optimised DP
    Let's Connect:
    📱Discord (Join Community) : / discord
    📝Linkedin: / aryan-mittal-0077
    📸 Instagram: / codewitharyanbhai
    💻 Twitter - / aryan_mittal007
    🤖 Github: github.com/ary...
    About Me:
    I am Aryan Mittal - A Software Engineer in Goldman Sachs, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)
    ✨ Hashtags ✨
    #programming #Interviews #leetcode #faang #maang #datastructures #algorithms

Комментарии • 9

  • @deepakchalla495
    @deepakchalla495 3 месяца назад +1

    Great Video.
    cant we just do the same using for loops
    vectorarr(n,1);
    while(k--)
    {
    for(int i=1;i

  • @srikarvinjamara2003
    @srikarvinjamara2003 3 месяца назад +1

    heyy @Aryan Mittal this was the code i had written during contest.
    int valueAfterKSeconds(int n, int k) {
    vector nums(n,1);
    for(int i = 0;i

  • @jatinjangra5278
    @jatinjangra5278 3 месяца назад +1

    actually we dont need to take two vectors , only one is enough

    • @raviprasath.k.j9462
      @raviprasath.k.j9462 3 месяца назад

      actually we don't need a vector if we do it math in O(n) complexity.
      class Solution:
      def valueAfterKSeconds(self, n: int, k: int) -> int:
      ans = 1
      mod = 1000000007
      for i in range(0,k) :
      ans = (ans*(n+i))%mod
      ans = (ans*pow(i+1,mod-2,mod))%mod
      return ans

  • @raviprasath.k.j9462
    @raviprasath.k.j9462 3 месяца назад

    I came with this solution in the contest in O(n) time complexity aryan if wonder if you could explain about modular inverse concept
    cauz the actual logic i thought is this
    class Solution:
    def valueAfterKSeconds(self, n: int, k: int) -> int:
    ans = 1
    mod = 1000000007
    for i in range(0,k) :
    ans = (ans*(n+i))%mod
    ans = (ans//(i+1))
    return ans
    but due to some reasons i got wrong answer I want to know why
    and i end up using this solution after hearing about modular inverse concept
    class Solution:
    def valueAfterKSeconds(self, n: int, k: int) -> int:
    ans = 1
    mod = 1000000007
    for i in range(0,k) :
    ans = (ans*(n+i))%mod
    ans = (ans*pow(i+1,mod-2,mod))%mod
    return ans

  • @ayushsrinivas
    @ayushsrinivas 3 месяца назад

    aryan you wrote code worng

  • @cse100amisha6
    @cse100amisha6 3 месяца назад

    class Solution {
    public:
    int valueAfterKSeconds(int n, int k) {
    int MOD=1e9+7;
    vector a(n,1);
    for(int i=0;i

  • @KunalSingh-ol6zx
    @KunalSingh-ol6zx 3 месяца назад

    koi mathematical formula?

  • @jd3287
    @jd3287 3 месяца назад

    nice!