Problem · Hash Table
EasyCitadelOA

Problem statement

There is a shop with old-style cash registers. Rather than scanning items and pulling the price from a database, the price of each item is typed in manually. This method sometimes leads to errors. Given a list of items and their correct prices, compare the prices to those entered when each item was sold. Determine the number of errors in selling prices.

Function

priceCheck(products: String[], productPrices: float[], productSold: String[], soldPrice: float[]) → int

Complete the function priceCheck in the editor.

priceCheck has the following parameter(s):

  1. 1. String[] products: each products[i] is the name of an item for sale
  2. 2. float[] productPrices: each productPrices[i] is the price of products[i]
  3. 3. String[] productSold: each productSold[i] is the name of a product sold
  4. 4. float[] soldPrice: each soldPrice[i] contains the sale price recorded for productSold[i]

Returns

int: the number of sale prices that were entered incorrectly

Examples

Example 1

products = ["eggs", "milk", "cheese"]productPrices = [2.89, 3.29, 5.79]productSold = ["eggs", "eggs", "cheese", "milk"]soldPrice = [2.89, 2.99, 5.97, 3.29]return = 2
Example 1 illustration
The second sale of eggs has a wrong price, as does the sale of cheese. There are 2 errors in pricing.

Constraints

  • 1 ≤ n ≤ m
  • 1 ≤ m ≤ n
  • |SP - productPrices[i], soldPrice[j]| ≤ 100000.00, where 0 ≤ i < n and 0 ≤ j < m

More Citadel problems

drafts saved locally
public int priceCheck(String[] products, float[] productPrices, String[] productSold, float[] soldPrice) {
  // write your code here
}
products["eggs", "milk", "cheese"]
productPrices[2.89, 3.29, 5.79]
productSold["eggs", "eggs", "cheese", "milk"]
soldPrice[2.89, 2.99, 5.97, 3.29]
expected2
checking account