Problem · Hash Table
Price Check
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.
Complete the function priceCheck in the editor.
priceCheck has the following parameter(s):
- 1.
String[] products: eachproducts[i]is the name of an item for sale - 2.
float[] productPrices: eachproductPrices[i]is the price ofproducts[i] - 3.
String[] productSold: eachproductSold[i]is the name of a product sold - 4.
float[] soldPrice: eachsoldPrice[i]contains the sale price recorded forproductSold[i]
Returns
int: the number of sale prices that were entered incorrectly
Examples
01 · 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

The second sale of eggs has a wrong price, as does the sale of cheese. There are 2 errors in pricing.
Constraints
1 ≤ n ≤ m1 ≤ m ≤ n|SP - productPrices[i], soldPrice[j]| ≤ 100000.00, where0 ≤ i < nand0 ≤ j < m
More Citadel problems
- Minimum Path Sum to Target in Binary TreePHONE SCREEN · Seen Apr 2026
- Social Media SuggestionsSeen May 2025
- Best Sum Downward Tree PathSeen May 2025
- Palindromic Substrings (LC 647 :)Seen Jan 2025
- Get Distinct Goodness ValuesSeen Jan 2025
- Get Min OperationsSeen Jan 2025
- Count Stable SegmentsSeen Jan 2025
- Find Consistent LogsSeen Oct 2024
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
sign in to submit