Number of Duplicates
Updated
Problem statement
You are given a list of n products. Product i has the name name[i], the price price[i] and the weight weight[i].
Two products are the same when they have the same name, the same price and the same weight. A product is a duplicate when the same product appears earlier in the list. So if one product appears 3 times, it counts as 2 duplicates.
Return the number of duplicate products in the list.
For example, let name = ["pen", "pen", "cup"], price = [1, 1, 1] and weight = [2, 2, 2]. The two pens are the same, so the second pen is a duplicate. The answer is 1.
Function
numDuplicates(name: List<String>, price: List<Integer>, weight: List<Integer>) → int
Complete the function numDuplicates in the editor.
numDuplicates has the following parameters:
List<String> name: the name of each productList<Integer> price: the price of each productList<Integer> weight: the weight of each product
Returns
int: the number of duplicate products
Examples
Example 1
name = ["ball", "box", "ball", "ball", "box"]price = [2, 2, 2, 2, 2]weight = [1, 2, 1, 1, 3]return = 2The products at indexes 0, 2 and 3 are all "ball" with price 2 and weight 1. The first one is the original, and the other two are duplicates. The two "box" products at indexes 1 and 4 weigh 2 and 3, so they are not the same. The answer is 2.
Example 2
name = ["ball", "box", "lamp", "brick", "pump"]price = [2, 2, 2, 2, 2]weight = [2, 2, 2, 2, 2]return = 0All five names are different, so no two products are the same. The answer is 0.
Constraints
1 <= n <= 10^5, wherenis the length ofname,priceandweight1 <= price[i], weight[i] <= 1000name[i]has 1 to 10 lowercase English letters ('a'to'z')
More Amazon interview questions
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Count Valid Square PairsAuxoAI · OA
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
- Customer Signer ScreeningState Farm · OA
- Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
- K Most Recent Unique Request IDsMicrosoft · OAMicrosoft interview questions
- Distinct Products After Removing One ElementHSBC · OAHSBC interview questions
- Filter Duplicates While Preserving OrderUpstart · OAUpstart interview questions