TopcoderArchiveVisit Topcoder
SRM2 Oct 2016
SRM 701

SquareFreeString

Problem statement, definition, constraints, and public examples.

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 String s. Return "square-free" if s is square-free. Otherwise, return "not square-free". Note that the return value is case-sensitive.

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

  1. "bobo"
    Returns: "not square-free"
    "bobo" = T + T, where T = "bo", so it is not square-free.
  2. "apple"
    Returns: "not square-free"
    Substring "pp" is a square.
  3. "pen"
    Returns: "square-free"
    "pen" does not contain any substrings that are squares.
  4. "aydyamrbnauhftmphyrooyq"
    Returns: "not square-free"
  5. "qwertyuiopasdfghjklzxcvbnm"
    Returns: "square-free"
Back to all problems