Count the Number of Powerful Integers | Digit DP | Hard Cases Problem

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 5. 01. 2024
  • In this video, I'll talk about how to solve Leetcode Count the Number of Powerful Integers
    Let's Connect:
    📝Linkedin: / aryan-mittal-0077
    📾 Instagram: / ez.pz.dsa
    đŸ“±Telegram : t.me/aryan_mittal_group
    đŸ€– Github: github.com/aryan-0077
    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 :)
    ✹ Timelines✹
    ✹ Hashtags ✹
    #programming #Interviews #leetcode #faang #maang #datastructures #algorithms

Komentáƙe • 10

  • @ARYANMITTAL
    @ARYANMITTAL  Pƙed 6 měsĂ­ci +5

    Considering the number of solutions, this problem got, i don't think, this was that easy, that it got 500 AC's, May be Constraints are the cause of it đŸ„¶

    • @bishalkundu7592
      @bishalkundu7592 Pƙed 6 měsĂ­ci

      Mass cheating 😂 bhaiyaa Ye toh har roz ka baat hai aj kaal

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 Pƙed 6 měsĂ­ci +1

    4th que that suffix matching was quite diff

  • @harikrushnasuhagiya3925
    @harikrushnasuhagiya3925 Pƙed 6 měsĂ­ci

    Thanks bhai

  • @phoddaal7130
    @phoddaal7130 Pƙed 6 měsĂ­ci

    Bhaiya Leading Zeroes wali cheese isme kyon use Karne ki zarurat nahi ho rhi ?

  • @gauravkabdwal309
    @gauravkabdwal309 Pƙed 6 měsĂ­ci

    Great!!

  • @SanjayKumar-iu7rq
    @SanjayKumar-iu7rq Pƙed 6 měsĂ­ci +1

    for num = 845, and limit = 6,
    According to your code
    for(int i=0;i

    • @yashvij21
      @yashvij21 Pƙed 6 dny

      He is wrong there actually it should not pass as tight for 6 . Ex: If maximum number is 8452 with suffix s="52" then 6652 is also valid answer. His code works right but in explanation he made a mistake.

  • @vanshbaghel5884
    @vanshbaghel5884 Pƙed 6 měsĂ­ci

    Bro please don't use red color, it's not lesser visible than others 😁
    Rest is good
    It is not working for java code:
    Code:
    static long[][] dp = new long[20][2];
    public static long numberOfPowerfulInt(long start, long finish, int limit, String s) {
    String r = Long.toString(finish);
    String l = Long.toString(start - 1);
    for (long[] row: dp) Arrays.fill(row, -1);
    long a = solve(r, s, 1, r.length(), limit);
    for (long[] row: dp) Arrays.fill(row, -1);
    long b = solve(l, s, 1, l.length(), limit);
    return a - b;
    }
    private static long solve(String num, String s, int tight, int n, int limit) {
    if (num.length() < s.length()) return 0;
    if (dp[n][tight] != -1) return dp[n][tight];
    // If tight hai, matlab if end is 3640 and current num is 3, then further nums cannot be greater than 640, else limit k upar hojayega, which will make it invalid. Therefore ub set krdo, ki iske upar nhi jaa skte, iske neeche hee raho.
    int ub = tight == 1 ? num.charAt(num.length() - n) - '0' : limit;
    long ans = 0;
    // Matlab, last number of num hua, toh check with s
    if (n == 1) {
    // last char check karo
    int lastCharOfS = s.charAt(s.length() - 1) - '0';
    // Agar ub se greater hai apna nums ka last number, tab 0 return krdo. EG:
    if (lastCharOfS > ub) return 0;
    return 1;
    }
    // Means s se peeche k numbers hai, toh limit se chhota hona chahiye, buss itna dhyaan rakho
    if (n ub) return 0;
    else if (correspondingSChar == ub) {
    ans = ans + solve(num, s, 1, n - 1, limit);
    return ans;
    // Means if corresponding s se smaller hai, ie,
    } else return 1;
    } else return 1;
    } else {
    for (int i = 0; i