Problem · Hash Table
Number of Duplicates
Learn this problemProblem statement
You are given a list of products, where each product has a name, price, and weight. Your task is to determine how many duplicate products are in the list. A duplicate product is defined as a product that has the same name, price, and weight as another product in the list.
Function Signature
public static int numDuplicates(List
Parameters:
List: A list of strings where name[i] represents the name of the product at index i.name List: A list of integers where price[i] represents the price of the product at index i.price List: A list of integers where weight[i] represents the weight of the product at index i.weight
Returns:
An integer denoting the number of duplicate products in the list.
Constraints
- 1 ≤ n ≤ 10^5
- 1 ≤ price[i], weight[i] ≤ 1000
- name[i] consists of lowercase English letters (a-z) and has at most 10 characters.
Function
numDuplicates(name: List<String>, price: List<Integer>, weight: List<Integer>) → intExamples
Example 1
name = ["ball", "box", "ball", "ball", "box"]price = [2, 2, 2, 2, 2]weight = [1, 2, 1, 1, 3]return = 2"ball" at indices [0, 2, 3] have the same attributes (name = "ball", price = 2, weight = 1), so there are 2 duplicates.
"box" at indices [1, 4] have different weights, so they are unique.
Example 2
name = ["ball", "box", "lamp", "brick", "pump"]price = [2, 2, 2, 2, 2]weight = [2, 2, 2, 2, 2]return = 0Each product has unique attributes, so there are no duplicates.
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026