Extra Characters in a String | Recursion | Bottom Up | Easy | Leetcode 2707 | codestorywithMIK

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

КОМЕНТАРІ • 55

  • @jabedhasan21
    @jabedhasan21 3 місяці тому +11

    The way you explain problems makes even hard ones feel easy. Thank you so much.

  • @theOmKumar
    @theOmKumar 2 місяці тому +4

    small optimisation: declare curr string outside the loop to avoid using substr function.. and keep adding characters to curr as we iterate in the inner loop.

  • @aws_handles
    @aws_handles 3 місяці тому +2

    Yaar aapne DP, Graph, Trie ka dar bhaga diya hai ❤❤❤

  • @AFFFFGAMER
    @AFFFFGAMER 3 місяці тому +5

    इसी वीडियो का इंतेजार कर रहे थे.❤

  • @gui-codes
    @gui-codes 3 місяці тому

    Yaar aap kitna sahi parhate ho. Literally I love your voice

  • @codePG-22
    @codePG-22 3 місяці тому +3

    I really like your videos, I would recommend to do codeforces problems or contests solutions as well that is real problem solving.

  • @yashwardhansingh8401
    @yashwardhansingh8401 3 місяці тому +1

    thank you 🥰 very much I am still doing POTD in my mid sem exam

  • @rockykumarverma980
    @rockykumarverma980 3 місяці тому +1

    Thank you so much Bhaiya ji 🙏🙏🙏

  • @kartikkaushik4743
    @kartikkaushik4743 3 місяці тому +8

    Radhe Radhe sir ji

  • @statusroom408
    @statusroom408 3 місяці тому +4

    Radhe Radhe

  • @KR_Technical-hj3bf
    @KR_Technical-hj3bf 3 місяці тому +7

    who is come directly on this video

    • @gui-codes
      @gui-codes 3 місяці тому

      me

    • @Code_loading
      @Code_loading 3 місяці тому

      ​@@gui-codesyou is English very nice

    • @code_buzz001
      @code_buzz001 3 місяці тому

      ​@@Code_loadingHe in is a university 😅

    • @aws_handles
      @aws_handles 3 місяці тому

      Me too

  • @gauravbanerjee2898
    @gauravbanerjee2898 2 місяці тому

    Thanks a lot bhaiya ❤❤

  • @Thescienceworld652
    @Thescienceworld652 2 місяці тому +1

    can I also use kmp algorithm?
    I will create a visited array initialised to 0 and have length equal to length of given string . now using Kmp , we can know which index is visited by every substring. after that we count number of 0's in visited array . this approach will take only N*K time complexity . where K is length of array.

  • @thefinalfit
    @thefinalfit 3 місяці тому

    Thanks a lot

  • @dubbingforfun8837
    @dubbingforfun8837 3 місяці тому +1

    Thank You Bhaiya (Red Heart)

  • @jeehub041
    @jeehub041 3 місяці тому +1

    Sir sirf memoization wale ka time complexity kya hoga n cube?

  • @ApiiiitaaaaPakoooodaaaaaa
    @ApiiiitaaaaPakoooodaaaaaa 2 місяці тому

    how do i think of the reverse iteration in the top down approach, i understoodd it, but unable to click
    please help sir

  • @akshatgoel149
    @akshatgoel149 3 місяці тому

    Pls make video on trie approach

  • @ShylessThakur
    @ShylessThakur 3 місяці тому +5

    Shooting this early morning..mik bhaiya ?

    • @codestorywithMIK
      @codestorywithMIK  3 місяці тому +9

      Yes i mostly record early morning.
      Least disturbance 😇❤️

    • @bathinabalaji4205
      @bathinabalaji4205 3 місяці тому

      @@codestorywithMIK can you suggest any coding sheet my OA and interviews are in some days

  • @kareni7572
    @kareni7572 2 місяці тому

    Why do we do take not take here when we can do all the things inside for loop like your other video?

  • @RahulRahul-rv7uh
    @RahulRahul-rv7uh 2 місяці тому

    Can you please suggest which Tab and which app are you using to make videos?

    • @codestorywithMIK
      @codestorywithMIK  2 місяці тому

      It’s ipad 11 pro.
      And i use the default app in it - Notes
      Hope that helps ❤️

  • @YogeshJangra-f6w
    @YogeshJangra-f6w 3 місяці тому

    Bhaiya aap bhi please ek DSA sheet bnadijiye pleasee

  • @rev_krakken70
    @rev_krakken70 3 місяці тому

    I was trying to use trie and in the process i messed up the code and got to incorrect answer..

  • @godessGOAT
    @godessGOAT 2 місяці тому

    bottom up approach me substring kese create ho rha hai mtlb, last to start, iam not getting it

    • @codestorywithMIK
      @codestorywithMIK  2 місяці тому +2

      The substring is being created here
      string curr = s.substr(i, j-i+1);
      i is the starting index and the length of the substring from i to j will be j-i+1

  • @md.taohidimamkhantamim9747
    @md.taohidimamkhantamim9747 3 місяці тому

    I've done in greedy approach but got WA in test case 1994. But still I'm confuse what's wrong with my approach. However can anyone tell me dp/recusion is the only way to solve this problem? Greedy approach won't work?

    • @harshittiwari5202
      @harshittiwari5202 3 місяці тому

      I had done similar to you , but after analysing my solution i knew my mistake... Basically I was finding the largest substring on any index that is present in dictionary and then moving to the end of substring but this approach is wrong because there is a possibility that a smaller substring might eventually have a longer substring....
      PS-I haven't studied DP till now

  • @kartikforwork
    @kartikforwork 2 місяці тому

    i like the way of converting code in bottom up, but i can't understand the what to use
    0...n or n....0 now. are both same? in every situation. pls stick to one way only

  • @peterfromengland8663
    @peterfromengland8663 3 місяці тому +3

    Ye dp itni hard kyu h🥹 ..can we always derive bottom up from top down ???? Please help❤😊

    • @lenovox1carbon664
      @lenovox1carbon664 3 місяці тому

      Yes its always possible, but in some problems it can be tricky.

    • @arjunkumaryadav8102
      @arjunkumaryadav8102 2 місяці тому

      Bhai bottom up. Ke jaruri hai uska state definition that is while memorizing what are u storing in each cell of used data structure for memoization....

  • @prathmeshkakde3731
    @prathmeshkakde3731 3 місяці тому

    aaj pehli bar na question samjha aur na solution..

    • @gui-codes
      @gui-codes 3 місяці тому

      bhai itna sahi to samjhaya hai. classic dp problem hai

  • @aizad786iqbal
    @aizad786iqbal 2 місяці тому

    but your old code was diff, usme toh ham for loop ke andar skip waala condition likhte they

    • @codestorywithMIK
      @codestorywithMIK  2 місяці тому

      We can do in both ways .
      Multiple ways to solve a problem

  • @sujayvikramgs8588
    @sujayvikramgs8588 3 місяці тому

    present

  • @expanse8846
    @expanse8846 2 місяці тому +2

    iterative khud krlia, just recursion sochne mai time lgta

  • @anmolverma075
    @anmolverma075 2 місяці тому

    Hi , In my java code I was getting an error ,
    class Solution {
    public int minExtraChar(String s, String[] dictionary) {
    HashSet set = new HashSet();
    int n = s.length();
    for(String str : dictionary){
    set.add(str);
    }
    return solve(0 , s , set , n);
    }
    public int solve(int i , String s , HashSet set , int len){
    if(i >= len){
    return 0;
    }
    int res = 1 + solve(i + 1 , s , set , len);
    for(int j = i ; j < len ; j++){
    String cur = s.substring(i , j - i+ 1);
    if(set.contains(cur)){
    res = Math.min(res , solve(j + 1, s , set , len));
    }
    }
    return res;
    }
    }
    When I did
    String cur = s.substring(i , j - i+ 1); I got and error but when I used
    String cur = s.substring(i , j + 1); , it ran successfully.
    Why is there a difference in this Java code and your C++ code?

    • @codestorywithMIK
      @codestorywithMIK  2 місяці тому +1

      In C++, substr is a member function of the std::string class that extracts a substring by specifying a starting position and an optional length. In Java, substring is a method of the String class, and you provide the start and end indices (end is exclusive). The key difference is that C++ allows you to specify the length of the substring, while Java requires both start and end indices for extracting the substring.

    • @anmolverma075
      @anmolverma075 2 місяці тому +2

      @@codestorywithMIK ok lord , got it
      Thanks for the explanation!

    • @codestorywithMIK
      @codestorywithMIK  2 місяці тому +1

      ❤️🙏 Most welcome

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 3 місяці тому +1

    i have done by trie and dp saw your trie video.
    class Node{
    Node[]child;
    boolean isEnd;
    public(){
    child=New node[26];
    isEnd =false;
    }
    }
    class Solution {
    public int minExtraChar(String s,String[]dict){
    Node root=new Node();
    for(String t:dict){
    insert(t,root);
    }
    int n=s.length();
    int[]dp=new int[n+1];
    for(int i=0;i