TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

CustomerWinBack

Problem statement, definition, constraints, and public examples.

Problem Statement

A store has decided to embark on a campaign to win back former customers that were lost to its competitors. First, it must check its sales records to determine which customers have not made purchases in the longest time. Customer information will be given as a String[], customers, where each element represents a single customer and is formatted as (quotes and brackets for clarity only): "<CUSTOMER_ID> <CUSTOMER_NAME>", where <CUSTOMER_ID> is an integer which uniquely identifies a customer, and <CUSTOMER_NAME> is the name of the customer. Sales records will be given as a String[], sales, where each element represents the most recent purchase by a single customer and is formatted as (quotes and brackets for clarity only): "<CUSTOMER_ID> <DAYS_ELAPSED>", where <CUSTOMER_ID> is an integer which corresponds directly to the <CUSTOMER_ID>s in customers, and <DAYS_ELAPSED> is the number of days since the store opened that the purchase was made. Given an int, currentDay, and an int, threshold, return the names of all the customers whose last purchase was made at least threshold days ago. currentDay is the number of days since the store first opened. The customer names should be returned as a String[] sorted in alphabetical order. If no customers meet the criteria, return an empty String[].

Definition

Class:
CustomerWinBack
Method:
formerCustomers
Parameters:
String[], String[], int, int
Returns:
String[]
Method signature:
String[] formerCustomers(String[] sales, String[] customers, int currentDay, int threshold)
(be sure your method is public)

Constraints

  • sales and customers will contain between 1 and 50 elements, inclusive.
  • Each element of sales will be formatted as "<CUSTOMER_ID> <DAYS_ELAPSED>" where: - <CUSTOMER_ID> is an integer between 0 and 100, inclusive, with no extra leading zeros. - <CUSTOMER_ID> exists in customers - <DAYS_ELAPSED> is an integer between 1 and currentDay, inclusive, with no extra leading zeros. - <CUSTOMER_ID> and <DAYS_ELAPSED> are separated by a single space.
  • There are no duplicate <CUSTOMER_ID>s in sales.
  • Each element of customers will contain between 3 and 50 characters, inclusive.
  • Each element of customers will be formatted as "<CUSTOMER_ID> <CUSTOMER_NAME>" where: - <CUSTOMER_ID> is an integer between 0 and 100, inclusive, with no extra leading zeros. - <CUSTOMER_NAME> contains only lowercase letters ('a'-'z') and is at least one letter long. - <CUSTOMER_ID> and <CUSTOMER_NAME> are separated by a single space.
  • There are no duplicate <CUSTOMER_ID>s or <CUSTOMER_NAME>s in customers.
  • currentDay is between 1000 and 10000, inclusive.
  • threshold is between 500 and 10000, inclusive.

Examples

  1. {"0 500", "1 501", "2 1"}
    {"1 sandberg", "2 davis", "0 thomas"}
    1000
    500
    Returns: { "davis",  "thomas" }
    It has been 1000 days since the store first opened. The most recent purchases of customers with ids 0 and 2 were made at least 500 days ago. The customer with id 0 is "thomas", and his last purchase was made when the store was open for 500 days (500 days ago). The customer with id 2 is "davis", and his last purchase was made when the store was open for 1 day (999 days ago). The returned String[] contains these two names in alphabetical order.
  2. {"0 1", "100 50"}
    {"40 joseph", "100 roger", "0 rogers"}
    6000
    4000
    Returns: { "roger",  "rogers" }
    Both customers in sales made their last purchases at least 4000 days ago. "roger" comes before "rogers" alphabetically.
  3. {"40 900", "20 1000", "0 5"}
    {"0 kingsley", "1 graham", "20 huxtable", "40 rivera"}
    1000
    4000
    Returns: { }
    The store has only been open for 1000 days, so there are no customers whose last purchases were made at least 4000 days ago. Therefore, an empty String[] is returned.
Back to all problems