Problem · Hash Table
Price Check
Learn this problemProblem 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.
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
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 Changes for a Periodic PalindromeOA · Seen Jul 2026
- Minimum Image Processing CostOA · Seen Jul 2026
- Minimum Path Sum to Target in Binary TreePHONE SCREEN · Seen Apr 2026
- Minimum Time to Process RequestsOA · Seen Mar 2026
- Process SchedulingOA · Seen Mar 2026
- Social Media SuggestionsSeen May 2025
- Best Sum Downward Tree PathSeen May 2025
- Palindromic Substrings (LC 647 :)Seen Jan 2025