TopcoderArchive
Archive
Algorithm problem

BrokenKeyboardRepair

Problem statement, definition, constraints, and public examples.

Problem Statement

All the alphabetical keys on your keyboard are broken. Given a String word, return the minimal number of keys you must repair to be able to type word.

Definition

Class:
BrokenKeyboardRepair
Method:
minimalNumberOfKeys
Parameters:
String
Returns:
int
Method signature:
int minimalNumberOfKeys(String word)
(be sure your method is public)

Constraints

  • word will contain between 1 and 50 characters, inclusive.
  • word will contain only lowercase letters ('a'-'z').

Examples

  1. "coder"
    Returns: 5
    You have to repair the following keys: 'c', 'd', 'e', 'o', 'r'.
  2. "hello"
    Returns: 4
    You have to repair the following keys: 'e', 'h', 'l', 'o'.
  3. "abracadabra"
    Returns: 5
    You have to repair the following keys: 'a', 'b', 'c', 'd', 'r'.
Back to all problems