Number of Duplicates
Updated
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[]) → intExamples
Example 1
name = ["ball", "box", "ball", "ball", "box"]price = [2, 2, 2, 2, 2]weight = [1, 2, 1, 1, 3]return = 2The 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 = 0All five products have different names, so none of them is a duplicate. The answer is 0.
Constraints
1 ≤ n ≤ 105, wherenisname.length. The listspriceandweightalso havenvalues.1 ≤ price[i], weight[i] ≤ 1000name[i]has 1 to 10 characters, all lowercase English letters (atoz)
More UKG interview questions
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