dynamic_programming.longest_common_substring ============================================ .. py:module:: dynamic_programming.longest_common_substring .. autoapi-nested-parse:: Longest Common Substring Problem Statement: Given two sequences, find the longest common substring present in both of them. A substring is necessarily continuous. Example: ``abcdef`` and ``xabded`` have two longest common substrings, ``ab`` or ``de``. Therefore, algorithm should return any one of them. Functions --------- .. autoapisummary:: dynamic_programming.longest_common_substring.longest_common_substring Module Contents --------------- .. py:function:: longest_common_substring(text1: str, text2: str) -> str Finds the longest common substring between two strings. >>> longest_common_substring("", "") '' >>> longest_common_substring("a","") '' >>> longest_common_substring("", "a") '' >>> longest_common_substring("a", "a") 'a' >>> longest_common_substring("abcdef", "bcd") 'bcd' >>> longest_common_substring("abcdef", "xabded") 'ab' >>> longest_common_substring("GeeksforGeeks", "GeeksQuiz") 'Geeks' >>> longest_common_substring("abcdxyz", "xyzabcd") 'abcd' >>> longest_common_substring("zxabcdezy", "yzabcdezx") 'abcdez' >>> longest_common_substring("OldSite:GeeksforGeeks.org", "NewSite:GeeksQuiz.com") 'Site:Geeks' >>> longest_common_substring(1, 1) Traceback (most recent call last): ... ValueError: longest_common_substring() takes two strings for inputs