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.

# Strange Counter

# Strange Counter

#### Sort by

recency

#### |

#### 963 Discussions

#### |

Please Login in order to post a comment

Here is my c++ solution, you can watch the explanation here : https://youtu.be/Plsx1i8dqiI

My solution in Java:

"The fastest way to loop is to not loop at all."

This function gets the number starting the next cycle, and subtracts 't' from it to get the result.

Ex: t=9 -> 10-9=1

Ex: t=7 -> 10-7=3

Ex: t=10 -> 22-10=12

Python 3

javasript

Python 3 solution.

Time complexity: O(log t)

Space complexity: O(1)