Problem · String
Greatest Common Divisor of Strings
Learn this problemProblem statement
A non-empty string t divides s when s is one or more concatenated copies of t.
Return the longest string that divides both str1 and str2, or the empty string when none exists.
Function
gcdOfStrings(str1: String, str2: String) → StringExamples
Example 1
str1 = "ABCABC"str2 = "ABC"return = "ABC""ABC" repeats twice to form the first string and once to form the second.
Constraints
1 <= str1.length, str2.length <= 100000- Both strings contain uppercase English letters.