Digit DP: Digit Sum | SPOJ

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

КОМЕНТАРІ • 41

  • @sarthaksharma6973
    @sarthaksharma6973 2 роки тому +7

    Sir please don't stop making videos. Like other UA-camrs I know you don't demand subscribers like such but your content is gold and one day people will come to know who is the best just keep moving forward. Educational content grows slowly on yt but it is really what change people's life.

  • @uptonogood300
    @uptonogood300 2 роки тому +2

    Alternate simpler approach we can just keep Sum of digit as parameter ,this way we don't need a separate count function
    ll helper(string &r, int sum=0,int digit=0,bool flag=true)
    {
    if(digit==r.size())
    {
    return sum;
    }
    if(dp[digit][sum][flag]!=-1)
    {
    return dp[digit][sum][flag];
    }
    int tight=(flag)? r[digit]-'0': 9;
    ll k=0;
    for(int i=0;i

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

    I messed up all digit dp problems during my campus placements...didn't even know how to solve them without brute force.Thank you for providing explanations!!I'm enjoying your videos a lot

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

    Your Teaching way is Extraordinary vaia,,
    Plz keep making videos.

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

    The Best Digit DP Series, I can say

  • @iamcrypticcoder
    @iamcrypticcoder 2 роки тому +1

    Nice explanation. Regarding the cnt() method. we can use following simplified imeplementation.
    LL cnt(string num, int n, int tight) {
    if (tight == 0) return (pow(10, n) + 0.1);
    if (n == 0) return 1;
    return stoll(num.substr(num.length()-n)) + 1;
    }

    • @ishmam8643
      @ishmam8643 2 роки тому

      We can also recursively count all the valid solutions and multiply them :)
      string s;
      ll dp[20][2], ans;
      ll cdp[20][2];
      ll cnt(int i, int j) {
      if (i == s.size()) return 1;
      ll& ret = cdp[i][j];
      if (~ret) return ret;
      ret = 0;
      int lim = (j ? s[i] - '0' : 9);
      for (int k = 0; k

    • @anuchan-l7y
      @anuchan-l7y 2 місяці тому

      Noicee

  • @vishnuvardhan-md1ux
    @vishnuvardhan-md1ux 3 роки тому +7

    Great explanation Bhaiya, but i have one question, while generating cnt(x) if tight ==1 why are you again using recursion instead of taking last n-1 digits? for example our range is 9863
    and we kept our first digit as 9 and since 9 is the maximum we can place in the first digit we need to know how many time 9 gets generated for that i can directly return 863 right if tight==0 then no issues i can return pow(10,n-1)? instead of doing recursion.

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому +8

      Hey Vishnu, nice observation.
      You are right if tight is 1 and number is 863, we can directly return 863+1(000, 001, 002, ... , 863).
      You can definitely solve it this way too. For me recursion seemed more consistent with the theme of the series digit dp.
      Also imagine if the number was 10000 digit long and you had to return cnt(x) % M.
      Hope that helps :)

    • @vishnuvardhan-md1ux
      @vishnuvardhan-md1ux 3 роки тому +3

      @@AlgosWithKartik Thanks Bhaiya.

  • @tonystarc9567
    @tonystarc9567 3 роки тому +2

    Thank you brother for everything you are doing... Please one request is do graphs and Union Find problems from Leetcode most frequently asked questions

  • @neerajpandey8159
    @neerajpandey8159 3 роки тому +3

    bhaiya at coder k dp problem set ki series baana do .ache questions h.plzzzzz

  • @ankitmindewar3710
    @ankitmindewar3710 3 роки тому +1

    its great, continue.

  • @gunjanbiswas925
    @gunjanbiswas925 3 роки тому

    awesome content bhaiya

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

    nice approach

  • @ananya8740
    @ananya8740 2 роки тому +1

    can we memoize the count function ?????

  • @harinath_mishra
    @harinath_mishra 3 роки тому +2

    Sir is there way to get editorials of spoj problems just like codeforces.

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому

      The best I can think of is to google search for "spoj problem code editorial"

  • @beingnikhil155
    @beingnikhil155 3 роки тому

    got ac first and then watched the video;)

  • @technophylic3321
    @technophylic3321 3 роки тому +2

    Sir please make a video on merge interval dp problems... ASAP, thank you for contributing it is very very helpful.

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому +2

      can you share an example problem which uses this technique?

    • @technophylic3321
      @technophylic3321 3 роки тому +1

      @@AlgosWithKartik and sir also the blog which you shared regarding dp patterns there are many more examples of these problems, such bust balloon etc.

  • @mayankverma3690
    @mayankverma3690 3 роки тому +1

    Sir don't worry soon You will have too many subscribers :)

  • @fardeen2158
    @fardeen2158 3 роки тому +3

    Thanku so much . Can you please start series for Graphs Algo ,Stl . i saw playist it have one video only for graph .By the way Your doing really amazing job bhaiya/

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому +1

      Thanks Fardeen!
      Yes I will try to start a series for graph sometime soon

  • @kannekantimanoj431
    @kannekantimanoj431 3 роки тому

    Is it really a dp problem, i feel like no sub problems will be repeated.

  • @hymnish_you
    @hymnish_you 2 роки тому

    Hey Bro, A silly doubt. Can we apply dp to postorder in an case? I meant, if rather than calculating count separately, can we directly send sum in next call postorder?
    Here is an example...
    ```
    private static long helper(long num, int x, boolean isTight, long sum){
    if(x == Long.toString(num).length()) return sum;
    int lb = 0;
    int ub = isTight ? Long.toString(num).charAt(x)-'0' : 9;
    long res = 0;
    for(int i = lb; i

    • @AlgosWithKartik
      @AlgosWithKartik  2 роки тому +1

      Try it out :) will need to watch my solution or think of it again before answering your query

    • @hymnish_you
      @hymnish_you 2 роки тому +1

      @@AlgosWithKartik No problem, I will try... While I always have hard time at making use of dp in postorder. And its always like we store values in preorder. Anyways thanks!!

  • @qazaqempire2446
    @qazaqempire2446 2 роки тому

    what is the level of difficulty here? is this problem hard?

  • @ManishaKumari-yv3nf
    @ManishaKumari-yv3nf 3 роки тому +2

    First comment

  • @anubhavsethi3416
    @anubhavsethi3416 3 роки тому

    which tool u r using for writing on screen ??

  • @RajatKumar-yi2cf
    @RajatKumar-yi2cf 3 роки тому

    Second comment 🔥

  • @em_nikhil_007
    @em_nikhil_007 3 роки тому +1

    7th comment 😂

  • @kuanbibadminton
    @kuanbibadminton 2 роки тому

    Can't hear your English:(