Problem Statement
We say that a string S is a square if it has the form TT, where T is some non-empty string. In other words, a square is a string that is a concatenation of two copies of the same non-empty string. For example, the strings "aa", "bbbb", and "beriberi" are squares.
A string is called square-free if none of its substrings is a square. For example, the string "abca" is square-free. (The substrings of this string are the strings "a", "b", "c", "a", "ab", "bc", "ca", "abc", "bca", and "abca". None of these strings is a square.)
You are given a
Definition
- Class:
- SquareFreeString
- Method:
- isSquareFree
- Parameters:
- String
- Returns:
- String
- Method signature:
- String isSquareFree(String s)
- (be sure your method is public)
Constraints
- s will consist only of lowercase English letters ('a'-'z').
- The length of s will be between 1 and 50, inclusive.
Examples
"w"
Returns: "square-free"
"cb"
Returns: "square-free"
"qok"
Returns: "square-free"
"aegi"
Returns: "square-free"
"oqquy"
Returns: "not square-free"
"ulhpnm"
Returns: "square-free"
"hncmexsslh"
Returns: "not square-free"
"psdurqrqdvmqgwplcktqejbhngvkjnrldskaxclvnblz"
Returns: "not square-free"
"wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy"
Returns: "not square-free"
"fcliblymyqckxvieotjotiqwtyznhvuhbaixwqnsytx"
Returns: "square-free"
"wobervhvkihcuyjtmqhaigvaheoqleromusrartldojsjvynfs"
Returns: "square-free"
"aydyamrbnauhftmphyroyqg"
Returns: "square-free"
"hncmexslhs"
Returns: "square-free"
"ijvxljt"
Returns: "square-free"
"qok"
Returns: "square-free"
"sijcwpcfrnlaqwdjftpxzrbtzil"
Returns: "square-free"
"cwlqeyjcukhsmumtesyoqjisfxqfgwjhx"
Returns: "square-free"
"rajcqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiyt"
Returns: "square-free"
"vmluxpwzhga"
Returns: "square-free"
"hncmexsxss"
Returns: "not square-free"
"rtcjbjlbtjrtcjbjlbtj"
Returns: "not square-free"
"wobervhvkihcuyjtmqhaigvaheoqleromusrartldoosjvynfs"
Returns: "not square-free"
"xiwpcfsmzenbvpdfpnduqienbvpdfpnduqiwngqb"
Returns: "not square-free"
"cwlqeyjcukhsmumtelqeyjcukhsmumtex"
Returns: "not square-free"
"qoo"
Returns: "not square-free"
"xtejpsfqyiplmyzuotbymtkcmuotbymtkcmrufgsyxmnqmc"
Returns: "not square-free"
"fcliblymyqckxvieotjotiqwtyznhtyznhixwqnsytx"
Returns: "not square-free"
"iraqgobfiaqgobfirhjcigigym"
Returns: "not square-free"
"porbdorbduvtu"
Returns: "not square-free"
"bobo"
Returns: "not square-free"
"bobo" = T + T, where T = "bo", so it is not square-free.
"apple"
Returns: "not square-free"
Substring "pp" is a square.
"pen"
Returns: "square-free"
"pen" does not contain any substrings that are squares.
"aydyamrbnauhftmphyrooyq"
Returns: "not square-free"
"qwertyuiopasdfghjklzxcvbnm"
Returns: "square-free"
"abb"
Returns: "not square-free"
"a"
Returns: "square-free"
"abca"
Returns: "square-free"
"ssa"
Returns: "not square-free"
"bobk"
Returns: "square-free"
"abcdeezyok"
Returns: "not square-free"
"xdyrthsyu"
Returns: "square-free"
"acba"
Returns: "square-free"
"abcabc"
Returns: "not square-free"
"bab"
Returns: "square-free"
"abc"
Returns: "square-free"
"abcdd"
Returns: "not square-free"
"aa"
Returns: "not square-free"
"bkmbod"
Returns: "square-free"
"abcadc"
Returns: "square-free"
"abcdefafagheih"
Returns: "not square-free"
"abcdab"
Returns: "square-free"
"bolo"
Returns: "square-free"
"aaa"
Returns: "not square-free"
"dfidhrgneijrwsjackjackjierkf"
Returns: "not square-free"
"aba"
Returns: "square-free"
"asdfghjklqwertyuiopzxcvbnvcc"
Returns: "not square-free"