Member-only story

Count the Duplicates (LeetCode Problem-Solving — 2)

Ankit Maheshwari
2 min readJan 12, 2025

--

“Count the duplicate number” problem: Count the duplicate values in the array, by modifying the containsDuplicate function from the blog Contains Duplicate (Problem-Solving — 1) to track how many times each number appears.

We will be using a Map or a plain JavaScript Object.

My articles are open for everyone; non-member readers can read the article by clicking this link.

If you haven’t read the “Duplicate Check” problem yet, I highly recommend reading it first before diving into this problem for a better understanding of the context.

Let’s Start…

1 — Count the duplicates:

Here is the modified function of containsDuplicate to count the duplicates, the output is a variable duplicateCount and will return how many values appear more than once:

--

--

Ankit Maheshwari
Ankit Maheshwari

Responses (1)