Keep Multiplying Found Values by Two

The problem requires us to continuously search for a number in the array and double it each time we find it. We stop when we can’t find the current number in the array and return this number.

Here is a Python solution:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Solution:
    def findFinalValue(self, nums: List[int], original: int) -> int:
        # Convert list to set for O(1) lookup
        num_set = set(nums)

        # Keep doubling original while it exists in nums
        while original in num_set:
            original *= 2

        # Return the final value of original
        return original

The solution begins by converting the input list nums to a set for faster lookup. It then enters a loop where it doubles original while original exists in the set. This process stops when original no longer exists in the set. The final value of original is then returned.

This has a time complexity of O(n), where n is the length of the input array nums, as each element is visited once when converting the list to a set. The space complexity is also O(n) due to the extra space required for the set.