LeetCode Entry

2154. Keep Multiplying Found Values by Two

19.11.2025 easy 2025 kotlin rust

First original=original 2 not in array

2154. Keep Multiplying Found Values by Two easy blog post substack youtube

c4be91d4-0c0e-4b50-bbd4-237ec2f1d49d (1).webp

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/1178

Problem TLDR

First original=original*2 not in array #easy

Intuition

Simulate the proces. Use hashset to speedup.

Approach

  • for 1000 elements O(n^2) is acceptable

Complexity

  • Time complexity: \(O(n + log(max))\)

  • Space complexity: \(O(n)\)

Code

// 15ms
    fun findFinalValue(n: IntArray, o: Int) =
        o shl (0..10).first { o shl it !in n }
// 0ms
    pub fn find_final_value(n: Vec<i32>, o: i32) -> i32 {
       o << (0..11).find(|b| !n.contains(&(o << b))).unwrap()
    }