The only difference between Substrings and Subsequences is that Substrings must contain consecutive characters too while Subsequences has NO such bound. Remember that both the Substrings and Subsequences must maintain the order of characters of its original String. So we don't keep any unnecessary suffix or prefix.įor distinction only and to make them easily detectable, some Substrings are capitalized in each Strings shown above, from which we can obtain both USA and USSR.įrom the String fwetUSSARrweUSASRadasdasd, we can take any of the Substrings USSAR or USASR which both of them can produce the Subsequences USA and USSR. For example: USSRAīut the problem has asked us to find the shortest Strings whose Subsequences can produce both of the names. another one to keep record of how many unique Strings are generated.īut first let us understand what type of Strings we are counting and to do that let's take an example: USAįor the above example (and others), all (meaning that they may contain unnecessary suffix and prefix) the possible Strings whose Subsequences can produce both the name is actually inifinite.one for memoizing the length of the shortest String.We will take two 2D arrays of size 31 x 31 (although we just need length of name1 * length of name2 for each test case but let's keep it this way just for the sake of ease of implementation and since neither it consumes a lot of memory), The problem statement has already mentioned that the length of the names (Strings) will not cross 30. What is Dynamic Programming ? - educative.ioĭynamic Programming, Memoization, Tabulation - (Video) Memoization (1D, 2D and 3D) - GeeksForGeeks Subarray/Substring vs Subsequence and Programs to Generate them - GeeksForGeeks We need to find some shortest possible Strings(meaning that they won't have any unnecessary suffix or prefix) that can produce the names as Subsequences and we have to output : Tags : String, Subsequence, Dynamic Programming, Memoization
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |