#K94752. Longest Common Substring Finder
Longest Common Substring Finder
Longest Common Substring Finder
Given two strings, find the longest common substrings between them. A substring is defined as a contiguous sequence of characters. If there are multiple longest common substrings, output all of them without duplicates in lexicographical order. In mathematical terms, if we denote the two strings by ( S_1 ) and ( S_2 ), then you are to find all substrings ( X ) such that ( X ) is a substring of both ( S_1 ) and ( S_2 ) and ( |X| ) is maximized. If no common substring exists, output an empty line.
inputFormat
The input consists of two lines. The first line contains the first string ( S_1 ), and the second line contains the second string ( S_2 ). Both strings consist of printable characters.
outputFormat
Output a single line containing the longest common substring(s) separated by a single space in lexicographical order. If there are no common substrings, output an empty line.## sample
ABABC
BABCA
BABC