TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

InventoryClearout

Problem statement, definition, constraints, and public examples.

Problem Statement

To make room for newer products, a store would like to sell off its most unpopular items by discounting their prices and moving them to the clearance section. First, it must check its inventory records and determine which products have been selling poorly. Product information will be given as a String[], products, where each element represents a single product and is formatted as (quotes and brackets for clarity only): "<PRODUCT_ID> <PRODUCT_NAME>", where <PRODUCT_ID> is an integer which uniquely identifies a product, and <PRODUCT_NAME> is the name of the product. Inventory records will be given as a String[], inventory, where each element represents a single product and is formatted as (quotes and brackets for clarity only): "<PRODUCT_ID> <QTY_ORDERED> <QTY_IN_STOCK>", where <PRODUCT_ID> is an integer which corresponds directly to the <PRODUCT_ID>s in products, <QTY_ORDERED> is the number of units that have been ordered and received from the distributor, and <QTY_IN_STOCK> is the number of units in stock that have not yet been sold. Given an int, threshold, return the names of all the products that have sold at or below threshold percent of their ordered quantity. The product names should be returned as a String[] sorted in alphabetical order. If no products meet the criteria, return an empty String[].

Definition

Class:
InventoryClearout
Method:
poorSellers
Parameters:
String[], String[], int
Returns:
String[]
Method signature:
String[] poorSellers(String[] inventory, String[] products, int threshold)
(be sure your method is public)

Constraints

  • inventory and products will each contain between 1 and 50 elements, inclusive.
  • Each element of inventory will be formatted as "<PRODUCT_ID> <QTY_ORDERED> <QTY_IN_STOCK>" where: - <PRODUCT_ID> is an integer between 0 and 100, inclusive, with no extra leading zeros. - <PRODUCT_ID> exists in products - <QTY_ORDERED> is an integer between 1 and 1000, inclusive, with no extra leading zeros. - <QTY_IN_STOCK> is an integer between 1 and <QTY_ORDERED>, inclusive, with no extra leading zeros. - <PRODUCT_ID>, <QTY_ORDERED>, and <QTY_IN_STOCK> are separated by single spaces.
  • There are no duplicate <PRODUCT_ID>s in inventory.
  • Each element of products will contain between 3 and 50 characters, inclusive.
  • Each element of products will be formatted as "<PRODUCT_ID> <PRODUCT_NAME>" where: - <PRODUCT_ID> is an integer between 0 and 50, inclusive, with no extra leading zeros. - <PRODUCT_NAME> contains only lowercase letters ('a'-'z') and is at least one letter long. - <PRODUCT_ID> and <PRODUCT_NAME> are separated by a single space.
  • There are no duplicate <PRODUCT_ID>s or <PRODUCT_NAME>s in products.
  • threshold is between 0 and 50, inclusive.

Examples

  1. {"0 200 99", "1 200 100", "2 404 404"}
    {"0 donut", "1 muffin", "2 celery"}
    50
    Returns: { "celery",  "muffin" }
    Products with ids of 1 and 2 sold at or below 50% of their ordered quantity. The product with id 1 is a "muffin". 200 units were ordered and 100 are still in stock, meaning that 50% were sold. The product with id 2 is "celery". 404 units were ordered and all of them are still in stock, meaning that 0% were sold. The returned String[] contains these two product names in alphabetical order.
  2. {"2 1000 900", "1 300 250"}
    {"0 towel", "1 waffleiron", "2 waffle"}
    20
    Returns: { "waffle",  "waffleiron" }
    Both products in inventory had sales of 20% or less. "waffle" comes before "waffleiron" alphabetically.
  3. {"100 900 1", "50 10 2", "0 555 55"}
    {"0 avocado", "50 cilantro", "100 tortilla"}
    0
    Returns: { }
    All of the products in inventory had sales greater than 0%, so an empty String[] is returned.
Back to all problems