LeetCode Challenge Day 65 β 2154. Keep Multiplying Found Values by Two
Nitin Ahirwal / November 19, 2025
Hey folks π
This is Day 65 of my LeetCode streak π
Todayβs problem is 2154 β Keep Multiplying Found Values by Two.
A fun simulation-style problem:
You repeatedly check whether your current number exists in the array β
if yes, double it and continue the process.
π‘ Intuition
The straightforward idea is:
- If the number is present β multiply by 2
- Otherwise β stop
However, repeatedly searching through the array is slow.
So to optimize, we use a Set, allowing constant-time lookups.
π Approach
- Convert the input
numsinto a Set for O(1) search. - While the current
originalvalue exists inside the Set:- Update
original = original * 2.
- Update
- When the number is no longer present, return the final value.
This ensures minimal overhead and avoids unnecessary repeated scans.
π Complexity
-
Time Complexity:
O(n)
Creating the Set takes O(n); the doubling process is very short. -
Space Complexity:
O(n)
A Set is used to store the list values.
π§βπ» Code (JavaScript)
var findFinalValue = function(nums, original) {
const set = new Set(nums);
while (set.has(original)) {
original *= 2;
}
return original;
};
π― Example
Input:
nums = [5,3,6,1,12], original = 3
Output:
24
Explanation:
3 is in nums β becomes 6
6 is in nums β becomes 12
12 is in nums β becomes 24
24 is not in nums, so we stop.
π§ Reflection
A clean demonstration of how hashing simplifies repeated search tasks.
By converting to a Set, the problem becomes a simple loop instead of repeated array scans.
See you tomorrow for Day 66! π
Happy Coding π¨βπ»β¨