Skip to content

LeetCode 961: N-Repeated Element in Size 2N Array#114

Merged
WazedKhan merged 4 commits intomainfrom
961-n-repeated-element
Jan 2, 2026
Merged

LeetCode 961: N-Repeated Element in Size 2N Array#114
WazedKhan merged 4 commits intomainfrom
961-n-repeated-element

Conversation

@WazedKhan
Copy link
Copy Markdown
Owner

@WazedKhan WazedKhan commented Jan 2, 2026

Summary by CodeRabbit

  • New Features

    • Added a solution for LeetCode problem 961 (N-Repeated Element in Size 2N Array) that detects the repeated element in a single pass.
  • Tests

    • Added test cases covering multiple input scenarios to validate the new solution.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 2, 2026

📝 Walkthrough

Walkthrough

Adds a new LeetCode solution for problem 961 and corresponding tests. The Solution.repeatedNTimes method scans the list and returns the first value seen twice using a hash-based container.

Changes

Cohort / File(s) Summary
Solution file
LeetCode/easy/n_repeated_element_961.py
New Solution class with repeatedNTimes(self, nums: List[int]) -> int that tracks seen values (hash/dict or set) and returns the first repeated element.
Tests
tests/test_leetcode_easy.py
Added test_repeated_n_times cases that import and assert Solution.repeatedNTimes across multiple inputs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A quick hop through numbers, swift and neat,
I spot the twin and skip a beat.
Hash in paw, I call it out—hooray!
One pass, one find, then off to play. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the LeetCode problem being solved (problem 961) and its exact name, directly matching the main change in the pull request.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
LeetCode/easy/n_repeated_element_961.py (1)

6-12: Consider using a set for cleaner, more idiomatic code.

The algorithm is correct and efficient. However, since the stored value in seen_hash is never used, a set would be more appropriate and memory-efficient than a dictionary.

🔎 Proposed refactor using set
     def repeatedNTimes(self, nums: List[int]) -> int:
-        seen_hash = {}  # this can solved with set as well
+        seen = set()
 
         for num in nums:
-            if num in seen_hash:
+            if num in seen:
                 return num
-            seen_hash[num] = 1
+            seen.add(num)
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e50da5 and 47e2b88.

📒 Files selected for processing (2)
  • LeetCode/easy/n_repeated_element_961.py
  • tests/test_leetcode_easy.py
🧰 Additional context used
🧬 Code graph analysis (1)
tests/test_leetcode_easy.py (1)
LeetCode/easy/n_repeated_element_961.py (2)
  • Solution (5-12)
  • repeatedNTimes (6-12)
🔇 Additional comments (1)
tests/test_leetcode_easy.py (1)

137-160: LGTM!

The test cases are comprehensive and cover all the key scenarios including edge cases (minimum size array, all elements the same, different positions of repeated elements, and various array sizes). The test structure follows pytest conventions correctly.


class Solution:
def repeatedNTimes(self, nums: List[int]) -> int:
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.

@WazedKhan
Copy link
Copy Markdown
Owner Author

@coderabbitai generate docstrings

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 2, 2026

✅ Actions performed

Initiated docstring generation; will generate only if new commits exist.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 2, 2026

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #115

Docstrings generation was requested by @WazedKhan.

* #114 (comment)

The following files were modified:

* `LeetCode/easy/n_repeated_element_961.py`
📝 Add docstrings to `961-n-repeated-element`
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
LeetCode/easy/n_repeated_element_961.py (1)

16-16: Fix grammatical error in comment.

The grammatical error "this can solved" was already flagged in a previous review and should be corrected to "this can be solved with a set as well".

🧹 Nitpick comments (1)
LeetCode/easy/n_repeated_element_961.py (1)

16-21: Consider using a set instead of a dictionary.

The implementation correctly identifies the repeated element. However, since you only check for presence and never use the dictionary values, a set would be more idiomatic and slightly more efficient.

🔎 Proposed refactor using a set
-        seen_hash = {}  # this can solved with set as well
+        seen = set()
 
         for num in nums:
-            if num in seen_hash:
+            if num in seen:
                 return num
-            seen_hash[num] = 1
+            seen.add(num)
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47e2b88 and 09dc02d.

📒 Files selected for processing (1)
  • LeetCode/easy/n_repeated_element_961.py
🔇 Additional comments (1)
LeetCode/easy/n_repeated_element_961.py (1)

5-15: LGTM! Well-documented method signature.

The class structure, method signature with type hints, and auto-generated docstring are all clear and follow Python conventions.

@WazedKhan WazedKhan merged commit b0ff36d into main Jan 2, 2026
3 checks passed
@WazedKhan WazedKhan deleted the 961-n-repeated-element branch January 2, 2026 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant