11/21/2023 0 Comments Minimum window substring javaSome people said it is O(N), but I think it is not. So total time complexity is O( len2 × len1).I found a solution based on Sliding Window Algorithm, but I cannot figure out the time complexity. Time complexity To fill in the cells in the dp table, each cell takes O(1) computation. ![]() So the total space complexity is O( len2 × len1). The dp table has ( len2 + 1) × len1 total cells. Complexity analysis Space complexity Let len1 and len2 be the length of s1 and s2 respectively. Find minimum window width in string x that contains all characters of another string y.For example: String x 'coobdafceeaxab' String y 'abc' The answer should be 5, because the shortest substring in x that contains all three letters of y is 'bdafc'. Post-processing Initialize: minLen = INT_MAX, start = -1. ![]() Working example Input s1 = "abadebdde" (9 characters), s2 = "abe" (3 characters) Filling up the dp table We can traverse the bottom row from left to right to find out which length is the smallest, and for the smallest length which index is the earliest possible index for the result. In this case the length is len = e - dp + 1.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |