TopcoderArchive
Archive30 Jul 2007
TCCC07 Round 3

SimilarPairs

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a String[] text. Concatenate all the elements to make one string. A pair of non-empty two non-overlapping substrings of equal length (A, B) is called k-similar if there are no more than k positions where A and B have different characters. Return the number of distinct strings that belong to at least one such pair.

Definition

Class:
SimilarPairs
Method:
howManyElements
Parameters:
String[], int
Returns:
int
Method signature:
int howManyElements(String[] text, int k)
(be sure your method is public)

Constraints

  • text will contain between 1 and 50 elements, inclusive.
  • Each element of text will contain between 1 and 50 characters, inclusive.
  • Each element of text will contain only lowercase letters ('a'..'z').
  • k will be between 0 and 2500, inclusive.

Examples

  1. {"abacd"}
    1
    Returns: 6
    The following strings each belong to at least one similar pair: "a", "b", "c", "d", "ab", "ac".
  2. {"aaaa"}
    0
    Returns: 2
  3. {"abcdefgh"}
    2
    Returns: 15
  4. {"a", "ab", "abc"}
    0
    Returns: 3
  5. {"abacd"}
    0
    Returns: 1
Back to all problems