Using while loop and hashmap in Python
\nclass Solution:\n    def smallestRepunitDivByK(self, k: int) -> int:\n        #edge case\n\t\tif k % 2 == 0 or k % 5 == 0: return -1\n\t\t\n\t\t#keep track of
```\nclass Solution:\n    def smallestRepunitDivByK(self, k: int) -> int:\n        #edge case\n\t\tif k % 2 == 0 or k % 5 == 0: return -1\n\t\t\n\t\t#keep track of the remainder\n        remain, length = 0, 0\n        found_so_far = set()\n        while remain not in found_so_far:\n            found_so_far.add(remain)\n            remain = (remain * 10 + 1) % k\n            length += 1\n        return length if remain == 0 else -1\n```
['Python', 'Python3']