TopcoderArchive
TCO7 Mar 2007
TCO07 Round 2

WordSplit

Problem statement, definition, constraints, and public examples.

Problem Statement

Given a string of lowercase letters, I want to split it up into pieces so that the letters in each piece are distinct. I want to form as few pieces as possible. Given theString return a String[] containing the pieces sorted alphabetically.

If more than one way of splitting is minimal, return the sorted sequence of pieces that is first lexicographically. That means that the first element in the sequence that differs is earlier alphabetically.

Definition

Class:
WordSplit
Method:
pieces
Parameters:
String
Returns:
String[]
Method signature:
String[] pieces(String theString)
(be sure your method is public)

Constraints

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

Examples

  1. "facetiously"
    Returns: {"facetiously" }
    No splits are required since all the letters are distinct.
  2. "aaaaa"
    Returns: {"a", "a", "a", "a", "a" }
    This is the only legal split.
  3. "aba"
    Returns: {"a", "ab" }
    We need one split to separate the 'a's. Our choices are a/ba or ab/a. We return the one whose pieces form the earlier sequence lexicographically.
Back to all problems