FastPrepProduct Record Search

Product Record Search

Wells Fargo logoWells Fargo● MediumFULLTIMEOA
Learn

Problem statement

A product catalog is represented by aligned arrays: productNames[i], prices[i], and productionYears[i] describe product i.

Answer a batch of exact-match queries. Query i uses queryFields[i], which is one of name, price, or year, and the string queryValues[i].

  • For name, compare the value directly with product names.
  • For price and year, parse the value as a base-10 integer.

Each searchable field is unique across the catalog. Return the matching product name for every query in input order, or the empty string if no product matches.

Build sorted indexes for the three fields and answer each query with binary search.

Function

searchProductRecords(productNames: String[], prices: int[], productionYears: int[], queryFields: String[], queryValues: String[]) → String[]

Examples

Example 1

productNames = ["laptop","mouse","phone"]prices = [1200,25,800]productionYears = [2022,2024,2023]queryFields = ["name","price","year","price"]queryValues = ["mouse","800","2022","999"]return = ["mouse","phone","laptop",""]

The first three queries match by name, price, and year. No product costs 999.

Example 2

productNames = ["book","camera"]prices = [15,500]productionYears = [2020,2021]queryFields = ["year","name","price"]queryValues = ["2021","book","15"]return = ["camera","book","book"]

Different searchable fields may resolve to the same product.

Example 3

productNames = ["desk","lamp","monitor"]prices = [300,40,250]productionYears = [2019,2020,2021]queryFields = ["name","year","price"]queryValues = ["chair","2025","1"]return = ["","",""]

All three exact-match queries are absent.

Constraints

  • 1 <= productNames.length <= 2 * 10^5.
  • productNames.length == prices.length == productionYears.length.
  • Product names are distinct lowercase identifiers of length 1 through 30.
  • 1 <= prices[i] <= 10^9, and prices are distinct.
  • 1900 <= productionYears[i] <= 2100, and production years are distinct.
  • 1 <= queryFields.length == queryValues.length <= 2 * 10^5.
  • Every query field is name, price, or year. Numeric query values use canonical base-10 notation.

More Wells Fargo problems

See Wells Fargo hiring insights
public String[] searchProductRecords(String[] productNames, int[] prices, int[] productionYears, String[] queryFields, String[] queryValues) {
  // write your code here
}
productNames["laptop","mouse","phone"]
prices[1200,25,800]
productionYears[2022,2024,2023]
queryFields["name","price","year","price"]
queryValues["mouse","800","2022","999"]
expected["mouse", "phone", "laptop", ""]
Checking account…