Skip to main content
Back to problems
#2154
Easy Algorithms

Keep multiplying found values by two

Array Hash Table Sorting Simulation
75.1% acceptance
Feb 25, 2026
1062
54
You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums. If original is found in nums, multiply it by two (i.e., set original = 2 * original). Repeat this process with the new number as long as you keep finding the number. Return the final value of original.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn find_final_value(nums: Vec<i32>, original: i32) -> i32 {
    use std::collections::HashSet;
    let set: HashSet<i32> = nums.into_iter().collect();
    let mut val = original;
    while set.contains(&val) {
      val *= 2;
    }
    val
  }
}