1071. Greatest Common Divisor of Strings

Practice Greatest Common Divisor of Strings for free on NudgeCode: Easy, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

A string t divides a string s if s is t repeated one or more times. Return the longest string that divides both str1 and str2, or "" if there is none.

Example

str1 = "ABABAB", str2 = "ABAB"  ->  "AB"
str1 = "LEET", str2 = "CODE"    ->  ""

Constraints