Keep Multiplying Found Values by Two

You are given an integer array nums and an integer original. While original appears in nums, replace original with 2 * original. When original is no longer in nums, stop and return its final value.

30:00

Keep Multiplying Found Values by Two
easy
Free written solution
Topics
Companies

You are given an integer array nums and an integer original. While original appears in nums, replace original with 2 * original. When original is no longer in nums, stop and return its final value.

Example 1:
Input: {"nums":[5,3,6,1,12],"original":3}
Output: 24
Constraints:
  • 1≤nums.length≤10001 \leq \text{nums.length} \leq 1000

  • 1≤nums[i],original≤10001 \leq \text{nums}[i], \text{original} \leq 1000

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[5,3,6,1,12],"original":3}

original starts at 3. Each lookup in nums would be a full scan, so put nums into a hash set first.

nums

5
3
6
1
12

seen = set(nums)

not built yet

original over time

3

next

Variables
VariableValue
original3
DepthFunction Call
Stack empty
0/9