LeetCode Challenge Day 46 β 3289. Get Sneaky Numbers
Nitin Ahirwal / October 31, 2025
Hey folks π
This is Day 46 of my LeetCode streak π
Todayβs problem is 3289. Get Sneaky Numbers β an easy array problem that involves finding two numbers that appear twice in the given array.
π Problem Statement
You are given an integer array nums of length n + 2 where every integer between 0 and n - 1 appears exactly once, except for two numbers that appear twice.
Return an array containing the two duplicated numbers.
Example 1:
Input: nums = [0, 1, 2, 3, 2, 5, 4, 5]
Output: [2, 5]
Example 2:
Input: nums = [0, 1, 2, 3, 0, 4, 5, 6]
Output: [0, 3]
π‘ Intuition
Since all numbers except two are unique,
we just need to detect which numbers appear twice.
A simple and efficient way to do this is to use a seen array or set β mark each number the first time it appears, and if it appears again, add it to the result.
π Approach
- Initialize a boolean array
seenof sizento track visited numbers. - Iterate through each element in
nums.- If a number is already marked in
seen, itβs a duplicate β add to result. - Otherwise, mark it as seen.
- If a number is already marked in
- Stop once both duplicates are found.
β±οΈ Complexity Analysis
-
Time complexity:
(O(n)) β Single pass through the array. -
Space complexity:
(O(n)) β Extra space for theseenarray.
π§βπ» Code (JavaScript)
/**
* @param {number[]} nums
* @return {number[]}
*/
var getSneakyNumbers = function(nums) {
const n = nums.length - 2; // since two numbers are duplicated
const seen = new Array(n).fill(false);
const res = [];
for (let num of nums) {
if (seen[num]) {
res.push(num);
if (res.length === 2) break; // found both sneaky numbers
} else {
seen[num] = true;
}
}
return res;
};
π§ͺ Example Walkthrough
Input:
nums = [0, 1, 2, 3, 2, 5, 4, 5]
Steps:
-
Seen = []
-
0 β mark seen
-
1 β mark seen
-
2 β mark seen
-
3 β mark seen
-
2 β already seen β add to result
-
5 β mark seen
-
4 β mark seen
-
5 β already seen β add to result
β
Output = [2, 5]
π― Reflection
A nice warm-up problem to strengthen your array manipulation and hashing intuition.
Simple yet satisfying β a perfect reminder that clean thinking leads to clean code β¨
Thatβs it for Day 46 of my LeetCode journey!
See you tomorrow for Day 47 π₯
Happy Coding π¨βπ»