TopcoderArchive
TCO24 Apr 2019
TCO19 SRM 756

PAndPuns

Problem statement, definition, constraints, and public examples.

Problem Statement

Kaede loves puns. You want to please her by telling her a pun.

Given the String text, you should return the String "pun" (quotes for clarity) if text is a pun. Otherwise, return "not a pun".

For the purpose of this problem, text is a pun if there exists some string S of length two or more that has two non-overlapping occurrences in text. (Each occurrence must be a contiguous substring of text, you may not skip letters.)

Definition

Class:
PAndPuns
Method:
check
Parameters:
String
Returns:
String
Method signature:
String check(String text)
(be sure your method is public)

Constraints

  • Length of text will be between 4 and 2,500, inclusive.
  • text will consist of lowercase English letters only ('a'-'z').

Examples

  1. "aaaa" 
    Returns: "pun"
    This is a pun because we can find two non-overlapping occurrences of the substring "aa".
  2. "aaab" 
    Returns: "not a pun"
    This is not a pun. Note that the two occurrences of "aa" in "aaab" overlap.
  3. "pandpuns" 
    Returns: "not a pun"
    "pan" and "pun" are similar but differ.
  4. "producerandproduction" 
    Returns: "pun"
Back to all problems