FastPrepNumber of Duplicates
Problems/Number of Duplicates

Number of Duplicates

Amazon logoAmazon● EasyOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

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 product
  • List<Integer> price: the price of each product
  • List<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 = 2

The 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 = 0

All five names are different, so no two products are the same. The answer is 0.

Constraints

  • 1 <= n <= 10^5, where n is the length of name, price and weight
  • 1 <= price[i], weight[i] <= 1000
  • name[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

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public static int numDuplicates(List<String> name, List<Integer> price, List<Integer> weight) {
      // write your code here
    }

}
Checking account…