FastPrepNumber of Duplicates
Problems/Number of Duplicates

Number of Duplicates

UKG logoUKG● EasyOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given a list of products. Product i has a name name[i], a price price[i] and a weight weight[i].

A product is a duplicate when an earlier product in the list has the same name, the same price and the same weight. Return how many duplicate products there are.

For example, if three products are all ("ball", 2, 1), the first one is not a duplicate and the other two are. That gives 2 duplicates.

Your function gets three lists of the same length. name is a list of strings. price and weight are lists of integers. It returns one integer, the number of duplicate products.

Function

numDuplicates(name: String[], price: int[], weight: int[]) → int

Examples

Example 1

name = ["ball", "box", "ball", "ball", "box"]price = [2, 2, 2, 2, 2]weight = [1, 2, 1, 1, 3]return = 2

The three "ball" products at indices 0, 2 and 3 all have price 2 and weight 1. The first is the original, so the other two are duplicates.

The two "box" products have different weights (2 and 3), so they are not duplicates. 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 products have different names, so none of them is a duplicate. The answer is 0.

Constraints

  • 1 ≤ n ≤ 105, where n is name.length. The lists price and weight also have n values.
  • 1 ≤ price[i], weight[i] ≤ 1000
  • name[i] has 1 to 10 characters, all lowercase English letters (a to z)

More UKG interview questions

  • Minimum Flips to Match Expected Binary Values in a TreeOA · Seen Mar 2025

Similar questions at other companies

  • Build the Task HierarchyPendo · OA
  • Macaron Order with Set DiscountsShopify · OAShopify interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Count Valid Square PairsAuxoAI · OA
  • Two SumAmazon · OA · PHONE SCREEN
  • 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
All UKG interview questionsSee UKG hiring insights
Saved
class Solution {
    public int numDuplicates(String[] name, int[] price, int[] weight) {
      // Write your code here
    }

}
Checking account…