Price Check
Updated
Problem statement
Given a shop's price list and its sales record, return the number of sales whose recorded price is wrong.
The shop uses old-style cash registers. Instead of scanning items and pulling the price from a database, the cashier types in the price of each item by hand, which sometimes leads to errors.
products[i]is the name of an item for sale, andproductPrices[i]is its correct price.productSold[j]is the name of the item in salej, andsoldPrice[j]is the price typed in for that sale.
A sale is an error when soldPrice[j] is not equal to the correct price of productSold[j].
Function
priceCheck(products: String[], productPrices: float[], productSold: String[], soldPrice: float[]) → intExamples
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| Product | Typed price | Correct price | Error |
|---|---|---|---|
| eggs | 2.89 | 2.89 | No |
| eggs | 2.99 | 2.89 | Yes |
| cheese | 5.97 | 5.79 | Yes |
| milk | 3.29 | 3.29 | No |
The second sale of eggs has a wrong price, as does the sale of cheese. There are 2 errors in pricing.
Example 2
products = ["apple", "bread", "juice"]productPrices = [1.25, 3.50, 4.00]productSold = ["bread", "bread", "apple"]soldPrice = [3.50, 3.50, 1.25]return = 0Both bread sales were typed in as 3.50 and the apple sale as 1.25. Each matches the correct price, so there are 0 errors.
Example 3
products = ["tea", "rice"]productPrices = [100000.00, 1.00]productSold = ["rice", "tea"]soldPrice = [1.01, 99999.99]return = 2Rice was typed in as 1.01 instead of 1.00, and tea as 99999.99 instead of 100000.00. A difference of one cent still counts, so there are 2 errors.
Constraints
1 <= n <= 10^5, wherenis the length ofproductsandproductPrices1 <= m <= 10^5, wheremis the length ofproductSoldandsoldPrice1.00 <= productPrices[i], soldPrice[j] <= 100000.00- Every price has at most two digits after the decimal point.
- All names in
productsare different. - Every name in
productSoldappears inproducts.
Similar questions at other companies
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Find Unique ElementsCisco · PHONE SCREENCisco interview questions
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Two SumAmazon · OA · PHONE SCREEN
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Two SumBNSF Railway · PHONE SCREENBNSF Railway interview questions
- Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
- Cross-Day User Trust ScoresAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions