We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The counter begins at 3. Each time it would tick down to zero, it instead “loops” up to double its previous maximum value, represented by "rem *= 2".
"t = t-rem" represents the counter ticking down before reinitializing. By subtracting the counter’s current maximum value directly from the remaining timer, we can skip looping the counter ticking "t" times, instead only following the number of times the counter itself loops back up from 0 within the bounds of t.
Once the remaining timer is less than the maximum counter, you’re in the final “loop” of the counter. The output is the value remaining on the counter once the timer runs out.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Strange Counter
You are viewing a single comment's thread. Return to all comments →
It's pretty straightforward: