TopcoderArchiveVisit Topcoder
SRM4 Feb 2006
SRM 287

CustomerStatistics

Problem statement, definition, constraints, and public examples.

Problem Statement

You will be given a String[] customerNames, containing a list of customer names extracted from a database. Your task is to report the customers that occur more than once in this list, and the number of occurrences for each of the repeated customers.

Your method should return the report as a String[]. Each element in this String[] should be of the form "NAME OCCURS", where NAME is the name of one customer and OCCURS is the number of times his name occurs in customerNames. Sort the result in alphabetical order by customer name.

Definition

Class:
CustomerStatistics
Method:
reportDuplicates
Parameters:
String[]
Returns:
String[]
Method signature:
String[] reportDuplicates(String[] customerNames)
(be sure your method is public)

Constraints

  • customerNames contains between 1 and 50 elements, inclusive.
  • Each element of customerNames contains between 1 and 50 characters, inclusive.
  • Each element of customerNames contains uppercase letters ('A'-'Z') only.

Examples

  1. {"JOHN", "BOB", "JOHN", "BILL", "STANLEY", "JOHN"}
    Returns: {"JOHN 3" }
    The only repeated name is JOHN, and it occurs three times.
  2. {"YETTI", "YETTI", "YETTI", "BIGFOOT", "BIGFOOT"}
    Returns: {"BIGFOOT 2", "YETTI 3" }
    Note the sorting order.
  3. {"ANDREW", "BILL", "CINDY", "DOH", "ERGH", "FOO", "GOO", "HMPH"}
    Returns: { }
    No repeated names this time.
  4. {"THEONLYCUSTOMER"}
    Returns: { }
    Again, no repeats.
  5. {"A", "B", "A", "C", "A", "B", "A", "D", "D", "D"}
    Returns: {"A 4", "B 2", "D 3" }
Back to all problems