LeetCode Entry
2154. Keep Multiplying Found Values by Two
First original=original 2 not in array
2154. Keep Multiplying Found Values by Two easy blog post substack youtube

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()
}