We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Substring Diff
Substring Diff
Sort by
recency
|
75 Discussions
|
Please Login in order to post a comment
You could definately just write a function to do both forloops cus the for loops are basically identical but ceebs. IF your wondering why theres two, i liook at all the diagonals sprouting from each edge of the index (top and left seperately) cus im not good enuff to do it in one loop. underwired sports bras
Very Beneficial for programers.
a modified version of the method for longest common substring, O(nm), each step in the matrix M takes constant time
for each i,j, this finds the longest consecutive common substring of s1, s2, ending at s1[i] and s2[j], then it takes the max of all these length
Didnt see a good python solution for this problem. Mine is O(n * m) solution (n,m are lens of s1 and s2).
It basically looks at diagonals how @bluephirus described it.
After reading @kiwi71728 comments, it explain great. My approach is different, but I don't have any strong theory, but the logic is the same with what kiwi71728 explain.
What I do is first create matrix difference.
From the matrix difference in there, I realized the the diagonal \ is the k we search. Then I add it to the list. From the matrix in there, the list become
Then loop again from the list to slice for each item in the list, the find the longest length if the sum is the same or less with k.