Click here to see the full article post
You can avoid using a map. You don't need all reminders to test for a cycle, you need only the first reminder of the cycle. For example, if you do 1 / 3 result is 0.(3). Now the tricky part - how to figure out which reminder is first in the cycle, because you can have 1 / 6 = 0.1(6), 1 is outside of the cycle. Think that numerator = 10^x * 2^x * 5^z * rest, where x, y, z can be 0. To get the first reminder of the cycle you need to skip x+y+z reminders. It works. This way you skip using HashMap because using HashMap is MAGNITUDES slower than integer operations, this code spends 90% if not more on HashMap calls.