TopcoderArchiveVisit Topcoder
TCO26 Mar 2014
TCO14 Round 1C

Unique

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a String S of lowercase English letters.

Some of the letters may occur multiple times in S. For example, there are three 'a's and two 'n's in "banana".

You dislike duplicates. For each letter, you want to keep only its first occurrence and delete all the others. Return the String obtained from S by deleting the duplicates of each letter, as described above.

Definition

Class:
Unique
Method:
removeDuplicates
Parameters:
String
Returns:
String
Method signature:
String removeDuplicates(String S)
(be sure your method is public)

Constraints

  • S will contain between 1 and 1000 characters, inclusive.
  • Each character of S will be a lowercase English letter ('a'-'z').

Examples

  1. "banana"
    Returns: "ban"
  2. "aardvark"
    Returns: "ardvk"
  3. "xxxxx"
    Returns: "x"
  4. "topcoder"
    Returns: "topcder"
Back to all problems