Your company is working on writing a piece of software to compress a text document. As part
of the software development team, you have been asked to write a function that will find the
longest repeated sub-string within a piece of text, such that the two chosen occurrences of the sub-string do not overlap. Your software is case sensitive, so two sub-strings are not the same if their capitalization differs. You have been instructed that, in a case where more than one such sub-string is the longest, the one that occurs earliest in the source string should be chosen.
For instance, given the string "ABCDABCFG", the longest repeated sub-string is "ABC". In the
string "ABABA", both "AB" and "BA" are repeated substrings, however, we choose "AB", since it occurs earlier. (Even though "ABA" appears twice as a
sub-string, the two occurrences overlaps, so that can not be used.)
You are given a String sourceText. You are to return a String
that is the longest repeated sub-string. If more than one substring of equal maximum length is repeated, return the one that occurs first in the string. If no sub-string repeats itself, return "".