FastPrepMap Order User IDs to Customer Names

Map Order User IDs to Customer Names

Crunchyroll logoCrunchyroll● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Three two-dimensional string arrays describe customer purchases, orders and products. Each customer buys one kind of product.

  • customers: [name,email,productName,quantity].
  • orders: [userId,email,totalAmount]; an order email may be missing.
  • products: [productName,unitPrice].

Return a mapping from each order user ID to a customer name using the following practice rules.

  1. For this exercise, assume a present order email matches the customer with exactly that email. Compare complete strings case-sensitively. The amount does not change this email match, and an unknown present email does not use fallback matching.
  2. For this exercise, assume a missing email is represented by an empty string. Compare the order amount with each customer’s quantity × unitPrice. Resolve the name only when exactly one customer row has that amount.
  3. For this exercise, assume unmatched or ambiguous orders resolve to an empty name. Two matching customer rows remain ambiguous even if their names are the same.

For this exercise, return a two-column string array [userId,resolvedName] with one row per order, in the original order sequence. Quantities and prices are exact base-10 integer strings; prices and amounts use the same smallest currency unit. Leading zeros do not change a number.

Function

mapOrderNames(customers: String[][], orders: String[][], products: String[][]) → String[][]

Examples

Example 1

customers = [["Ada", "ada@example", "Book", "2"], ["Ben", "ben@example", "Pen", "3"]]orders = [["u1", "ada@example", "7"], ["u2", "", "600"], ["u3", "absent@example", "600"]]products = [["Book", "500"], ["Pen", "200"]]return = [["u1", "Ada"], ["u2", "Ben"], ["u3", ""]]

This authored example uses a known email independently of amount, a unique missing-email subtotal, and an unknown present email that does not fall back.

Example 2

customers = [["Ada", "a", "Book", "2"], ["Ben", "b", "Game", "1"]]orders = [["u1", "", "1000"], ["u2", "a", "1000"]]products = [["Book", "500"], ["Game", "1000"]]return = [["u1", ""], ["u2", "Ada"]]

This authored missing-email order has two matching customer rows, while its known-email sibling identifies Ada.

Example 3

customers = []orders = [["u1", "", "0"]]products = []return = [["u1", ""]]

This authored order has no customer candidate; keep its user ID with an empty name.

Constraints

  • For this exercise, assume each table contains 0 through 100 rows with exactly its stated number of columns.
  • For this exercise, assume product names, customer emails and order user IDs are unique within their respective tables. Every customer product name exists in products.
  • For this exercise, assume quantity and unit price are in [1,10^6], and order amount is in [0,10^12]. Numeric strings contain only base-10 digits and have at most 13 characters.
  • For this exercise, assume names and identifiers are nonempty printable ASCII strings of at most 50 characters; only a missing order email is empty.

More Crunchyroll problems

See Crunchyroll hiring insights
public String[][] mapOrderNames(String[][] customers, String[][] orders, String[][] products) {
    // Write your code here.
    return new String[0][0];
}
customers[["Ada", "ada@example", "Book", "2"], ["Ben", "ben@example", "Pen", "3"]]
orders[["u1", "ada@example", "7"], ["u2", "", "600"], ["u3", "absent@example", "600"]]
products[["Book", "500"], ["Pen", "200"]]
expected[["u1", "Ada"], ["u2", "Ben"], ["u3", ""]]
Checking account…