We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 041b5e1 commit 8a9a20eCopy full SHA for 8a9a20e
interview_query/Maximum Common Substring
@@ -0,0 +1,15 @@
1
+Given two strings, write a function max_common_substring that finds the longest common substring between the input strings.
2
+
3
+A substring is a contiguous sequence of characters within a string. If there is no common substring, your function should return an empty string.
4
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
5
+def max_common_substring(str1, str2):
6
+ res = ''
7
+ start = 0
8
+ for i in range(len(str1)+1):
9
+ cur = str1[start:i]
10
+ if cur in str2:
11
+ if len(cur) > len(res):
12
+ res = cur
13
+ else:
14
+ start+=1
15
+ return res
0 commit comments