Connection Status:
Competition Arena > CustomerStatistics
SRM 287 · 2006-02-04 · by misof · Sorting
Class Name: CustomerStatistics
Return Type: String[]
Method Name: reportDuplicates
Arg Types: (vector<string>)
Problem Statement

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.

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
0)
{"JOHN", "BOB", "JOHN", "BILL", "STANLEY", "JOHN"}
Returns: {"JOHN 3" }

The only repeated name is JOHN, and it occurs three times.

1)
{"YETTI", "YETTI", "YETTI", "BIGFOOT", "BIGFOOT"}
Returns: {"BIGFOOT 2", "YETTI 3" }

Note the sorting order.

2)
{"ANDREW", "BILL", "CINDY", "DOH", "ERGH", "FOO", "GOO", "HMPH"}
Returns: { }

No repeated names this time.

3)
{"THEONLYCUSTOMER"}
Returns: { }

Again, no repeats.

4)
{"A", "B", "A", "C", "A", "B", "A", "D", "D", "D"}
Returns: {"A 4", "B 2", "D 3" }

Submissions are judged against all 94 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class CustomerStatistics with a public method vector<string> reportDuplicates(vector<string> customerNames) · 94 test cases · 2 s / 256 MB per case

Submitting as anonymous