TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

Palindromes

Problem statement, definition, constraints, and public examples.

Problem Statement

A palindrome is a string of length 1 (one) or greater that is the same both forwards and backwards. Examples are "AGA", "HANNAH", and "RACECAR".

Given a String word, calculate the number of unique palindromes that can be made out of the characters in word, using each character exactly once (see examples).

Definition

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

Constraints

  • word has length between 1 and 17, inclusive.
  • word will contain only capital letters ('A'-'Z').

Examples

  1. "ABB"
    Returns: 1
    The only palindrome is "BAB".
  2. "ABBA"
    Returns: 2
    The two legal palindromes are "ABBA" and "BAAB".
  3. "AMBSEAMBS"
    Returns: 24
  4. "ABC"
    Returns: 0
  5. "AABBCCDDEEFFGGHHI"
    Returns: 40320
Back to all problems