Count Sales Rung Up at the Wrong Price
Updated
Problem statement
A store keeps a price list: products[i] is a product name and prices[i] is its correct price in cents.
It also has a record of its sales: sale j sold the product soldProducts[j] and charged soldPrices[j] cents.
A sale is an error when the amount charged is not the correct price of the product that was sold. Each sale is checked on its own, so a product that was sold wrong three times gives three errors.
Return the number of errors.
Function
countPriceErrors(products: String[], prices: int[], soldProducts: String[], soldPrices: int[]) → intExamples
Example 1
products = ["pen","ink","pad"]prices = [150,899,425]soldProducts = ["ink","pen","ink","pad","pen"]soldPrices = [899,125,989,425,150]return = 2The correct prices are pen 150, ink 899 and pad 425 cents.
- Sale 0:
inkat 899. Correct. - Sale 1:
penat 125, but it should be 150. Error. - Sale 2:
inkat 989, but it should be 899. Error. - Sale 3:
padat 425. Correct. - Sale 4:
penat 150. Correct.
There are 2 errors.
Example 2
products = ["tea","mug"]prices = [300,1200]soldProducts = ["mug","tea"]soldPrices = [1200,300]return = 0Both sales use the correct price, so there are 0 errors.
Example 3
products = ["lamp","bulb"]prices = [4999,250]soldProducts = ["bulb","bulb","bulb"]soldPrices = [205,250,520]return = 2Each sale is checked on its own. bulb should cost 250. The sales at 205 and 520 are wrong and the one at 250 is right, so the answer is 2. lamp is never sold, which is fine.
Constraints
1 <= products.length <= 1000prices.length == products.length1 <= soldProducts.length <= 5000soldPrices.length == soldProducts.length- Every name has 1 to 10 characters, all lowercase English letters.
- The names in
productsare all different. - Every name in
soldProductsappears inproducts. 1 <= prices[i], soldPrices[j] <= 10^7
More DocuSign Online Assessment questions
- Max Sum With No Two Adjacent PicksOA · Seen Apr 2026
- Max Sum With No Two Adjacent Picks on a CircleOA · Seen Apr 2026
- Beautiful Number OrderingsOA · Seen Feb 2026
- Grid Path With the Most ClearanceOA · Seen May 2025
- Vehicle Mixes for a Wheel TotalOA · Seen May 2025
- Most Disjoint Intervals From Starts and DurationsOA · Seen Feb 2021
- Fewest Fountains to Water the GardenOA · Seen Feb 2021
- Lowest Start That Keeps Running Totals PositiveOA · Seen Feb 2021
- Fewest Student Groups Within a Level GapOA · Seen Nov 2020
- Alphabetize a Word ListOA · Seen May 2020
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
- Customer Signer ScreeningState Farm · OA
- String-Pair Frequency SimilarityIBM · OAIBM interview questions
- Number-Character Bijective MappingAdobe · OAAdobe interview questions
- Unique Difference PatternMicrosoft · OAMicrosoft interview questions
- Filter Transaction Logs and Calculate Reliability MetricsStripe · OAStripe interview questions
- Nonzero Totals by NameEPAM · OAEPAM interview questions
- Palindrome-Rearrangeable PairsExpedia · OAExpedia interview questions