TopcoderArchiveVisit Topcoder
SRM22 Dec 2013
SRM 617

FarStrings

Problem statement, definition, constraints, and public examples.

Problem Statement

All strings in this problem are strings of lowercase English letters ('a'-'z').

Given two strings S and T, their edit distance is defined as the smallest number of steps in which we can change S to T. In each step, we are allowed to make one of the following changes:
  • Erasing one arbitrary character of S.
  • Inserting one arbitrary character anywhere into S (including its beginning or end).
  • Replacing one arbitrary character of S by a different character.

For example:
  • The edit distance between "color" and "coord" is 2.
  • The edit distance between "banana" and "bnn" is 3.
  • The edit distance between "aaaa" and "bbbb" is 4.

You are given a String t. Let n be the length of t. Return a String[] with n elements. For each i, element i (0-based index) of the returned String[] must be the lexicographically smallest string with n characters such that the edit distance between t and the string is exactly i+1.

Definition

Class:
FarStrings
Method:
find
Parameters:
String
Returns:
String[]
Method signature:
String[] find(String t)
(be sure your method is public)

Notes

  • You may assume that for each valid test case there is at least one n-character string with each of the required edit distances.

Constraints

  • t will contain between 1 and 25 characters, inclusive.
  • Each character in t will be a lowercase English letter ('a'-'z').

Examples

  1. "atan"
    Returns: {"aaan", "aaaa", "aaba", "babb" }
    Let d(s,u) denote the edit distance between the strings s and u. The return value shown above is correct because: d("atan", "aaan") = 1: we can change 't' to 'a'. d("atan", "aaaa") = 2: we can change 't' to 'a' and then 'n' to 'a'. d("atan", "aaba") = 3: one shortest sequence of changes is "atan" -> "aan" -> "aab" -> "aaba". d("atan", "babb") = 4: one shortest sequence of changes is "atan" -> "aan" -> "ban" -> "bab" -> "babb". The strings "aaan", "aaaa", "aaba", and "babb" are the lexicographically smallest strings with the given edit distance from "atan".
  2. "ir"
    Returns: {"ar", "aa" }
  3. "aaa"
    Returns: {"aab", "abb", "bbb" }
  4. "bazinga"
    Returns: {"aazinga", "aaainga", "aaaanga", "aaaaaga", "aaaaaaa", "aaaaaab", "abbaabb" }
  5. "bcdab"
    Returns: {"acdab", "aadab", "aaaab", "aaaaa", "aaaca" }
Back to all problems