FastPrepProduct Record Search

Product Record Search

Wells Fargo logoWells Fargo● MediumFULLTIMEOA

Updated

Problem statement

You are given a product catalog as three arrays that line up by position: productNames[i], prices[i], and productionYears[i] describe product i.

You also get a list of exact-match queries. Query i looks in the field queryFields[i], which is name, price, or year, for the string queryValues[i].

  • For name, compare the value with the product names as it is.
  • For price and year, read the value as a base-10 integer first.

No two products share a name, a price, or a production year. For each query, in order, return the name of the matching product, or the empty string if no product matches.

Build a sorted index for each of 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 name query finds mouse. The price query finds phone, and the year query finds laptop. No product costs 999, so the last answer is the empty string.

Example 2

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

The year query finds camera. The name query and the price query both find book, so the same product can match more than once. The answer lists book twice.

Example 3

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

No product is named chair, and no product has the queried year or price. All three answers are the empty string.

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 are written in standard base-10 form.

More Wells Fargo Online Assessment questions

Similar questions at other companies

Interview reports that mention this question

Wells Fargo interview experiences

All Wells Fargo interview questionsSee Wells Fargo hiring insights
Saved
class Solution {
    public String[] searchProductRecords(String[] productNames, int[] prices, int[] productionYears, String[] queryFields, String[] queryValues) {
      // write your code here
    }
}
Checking account…