Skip to content

Add solution for "The Two Sneaky Numbers of Digitville" with unit tests. - #37

Merged
kobukuro merged 1 commit into
mainfrom
feat/the-two-sneaky-numbers-of-digitville
Jan 12, 2026
Merged

kobukuro merged 1 commit into
mainfrom
feat/the-two-sneaky-numbers-of-digitville

Conversation

@kobukuro

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings January 12, 2026 01:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a solution for LeetCode problem #3289 "The Two Sneaky Numbers of Digitville" with corresponding unit tests. The solution finds two numbers that appear twice in an array using a HashSet-based approach with O(n) time complexity.

Changes:

  • Implemented getSneakyNumbers method using HashSet to track seen numbers and identify duplicates
  • Added three test cases covering the provided problem examples
  • Included complexity analysis documentation

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
TheTwoSneakyNumbersOfDigitville3289.java Main solution implementation using HashSet to find duplicate numbers with early termination optimization
TheTwoSneakyNumbersOfDigitville3289Test.java Unit tests with three example test cases that sort results before comparison

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +16
/**
* Finds the two numbers that appear twice in the array.
* <p>
* Time Complexity: O(n) where n is the length of the array.
* We iterate through the array once, and HashSet operations (add, contains) are O(1) on average.
* <p>
* Space Complexity: O(n) for the HashSet to store seen numbers.
* In the worst case, we store almost all numbers before finding the duplicates.
*/

Copilot AI Jan 12, 2026

Copy link

Choose a reason for hiding this comment

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

The documentation style is inconsistent with the rest of the codebase. Other solution files in this repository use multi-line block comments with /* / format for complexity analysis, rather than Javadoc-style /* */ comments. Consider changing to the standard block comment format used in files like ContainsDuplicate217.java and TwoSum1.java for consistency.

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +49
@Test
void testGetSneakyNumbers_Example1() {
int[] nums = {0, 1, 1, 0};
int[] expected = {0, 1};

int[] result = solution.getSneakyNumbers(nums);
Arrays.sort(result);

assertArrayEquals(expected, result);
}

@Test
void testGetSneakyNumbers_Example2() {
int[] nums = {0, 3, 2, 1, 3, 2};
int[] expected = {2, 3};

int[] result = solution.getSneakyNumbers(nums);
Arrays.sort(result);

assertArrayEquals(expected, result);
}

@Test
void testGetSneakyNumbers_Example3() {
int[] nums = {7, 1, 5, 4, 3, 4, 6, 0, 9, 5, 8, 2};
int[] expected = {4, 5};

int[] result = solution.getSneakyNumbers(nums);
Arrays.sort(result);

assertArrayEquals(expected, result);
}

Copilot AI Jan 12, 2026

Copy link

Choose a reason for hiding this comment

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

The test coverage could be improved with additional edge cases. Other test files in this repository (e.g., MergeSortedArray88Test.java) include more comprehensive test coverage beyond just the provided examples. Consider adding tests for edge cases such as: a minimal array where n=2 (e.g., [0, 0]), cases where duplicates appear consecutively, or cases where duplicates are at the start or end of the array.

Copilot uses AI. Check for mistakes.
@kobukuro
kobukuro merged commit 8f69ea8 into main Jan 12, 2026
7 checks passed
@kobukuro
kobukuro deleted the feat/the-two-sneaky-numbers-of-digitville branch January 12, 2026 01:48
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.

2 participants