Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created November 19, 2025 22:36
Show Gist options
  • Select an option

  • Save Ifihan/3917613068cd6752c0c176a49c318c4b to your computer and use it in GitHub Desktop.

Select an option

Save Ifihan/3917613068cd6752c0c176a49c318c4b to your computer and use it in GitHub Desktop.
Keep Multiplying Found Values by Two

Question

Approach

I convert nums to a set for O(1) lookup. Then I repeatedly check if original is in the set; if it is, I double it. If not, I stop and return the final value.

Implementation

class Solution:
    def findFinalValue(self, nums: List[int], original: int) -> int:
        s = set(nums)
        
        while original in s:
            original *= 2
        
        return original

Complexities

  • Time: O(n)
  • Space: O(n)
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment