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 👨💻✨