Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LeetCode/easy/n_repeated_element_961.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 961. N-Repeated Element in Size 2N Array
# Link: https://leetcode.com/problems/n-repeated-element-in-size-2n-array/description/?envType=daily-question&envId=2026-01-02
from typing import List

class Solution:
def repeatedNTimes(self, nums: List[int]) -> int:
"""
Finds the element that appears N times in an array of length 2N.

Parameters:
nums (List[int]): An array of length 2N containing exactly one value repeated N times and the remaining N values distinct.

Returns:
int: The value that appears N times in `nums`.
"""
seen_hash = {} # this can solved with set as well
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix grammatical error in comment.

The comment has a grammar issue: "this can solved" should be "this can be solved".

🔎 Proposed fix
-        seen_hash = {}  # this can solved with set as well
+        seen_hash = {}  # this can be solved with set as well
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
seen_hash = {} # this can solved with set as well
seen_hash = {} # this can be solved with set as well
🤖 Prompt for AI Agents
In LeetCode/easy/n_repeated_element_961.py around line 7, the inline comment
reads "this can solved with set as well" which is grammatically incorrect;
update it to "this can be solved with a set as well" (or "this can also be
solved with a set") to correct grammar and improve clarity.


for num in nums:
if num in seen_hash:
return num
seen_hash[num] = 1
25 changes: 25 additions & 0 deletions tests/test_leetcode_easy.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,28 @@ def test_longest_common_prefix(strs, expected):

solution = Solution()
assert solution.longestCommonPrefix(strs) == expected

# https://leetcode.com/problems/n-repeated-element-in-size-2n-array/description/?envType=daily-question&envId=2026-01-02
# 961. N-Repeated Element in Size 2N Array


@pytest.mark.parametrize(
"nums, expected",
[
([1, 2, 3, 3], 3), # Example 1
([2, 1, 2, 5, 3, 2], 2), # Example 2
([5, 1, 5, 2, 5, 3, 5, 4], 5), # Example 3
([1, 1], 1), # Minimum size array
([4, 4, 4, 4], 4), # All elements are the same
([1, 2, 3, 4, 5, 5], 5), # Repeated element at the end
([6, 7, 8, 9, 6, 6], 6), # Repeated element at the beginning
([10, 20, 10, 30, 10, 40], 10), # Non-consecutive repeats
([100, 200, 300, 100, 400, 100], 100), # Larger numbers
([0, 0, 0, 0], 0), # All zeros
],
)
def test_repeated_n_times(nums, expected):
from LeetCode.easy.n_repeated_element_961 import Solution

solution = Solution()
assert solution.repeatedNTimes(nums) == expected
Loading