Skip to content
Discussion options

You must be logged in to vote

We need to repeatedly check if the current value of original exists in the given array nums. If it does, we double original and continue checking. This process stops when original is no longer found in nums.

Approach:

  1. Efficient Lookup: Convert the array nums into a set for O(1) average time complexity lookups.
  2. Iterative Checking: Continuously check if the current value of original exists in the set. If it does, double original and repeat the process. If not, return the current value of original.

Let's implement this solution in PHP: 2154. Keep Multiplying Found Values by Two

<?php
/**
 * @param Integer[] $nums
 * @param Integer $original
 * @return Integer
 */
function findFinalValue($nums

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Nov 19, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Nov 19, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants