C++ | SC: O(N), TC: O(N) | Explained Code
\nclass Solution {\npublic:\n    int smallestRepunitDivByK(int k) {\n        /*\n        Here, for example n = 1111, and k = 7\n        so, if the remainder of 
```\nclass Solution {\npublic:\n    int smallestRepunitDivByK(int k) {\n        /*\n        Here, for example n = 1111, and k = 7\n        so, if the remainder of 1111 / 7 = 5\n        then (5*10)%7 + 1 == 11111 % 7\n        LHS = 50%7 + 1 = 2\n        RHS = 2\n        \n        Q: How do we know that there will be no \'n\' divisible by \'k\'?\n        A: If we find a cycle, if same remainder is repeated, that means we will always get the same result in a cycle\n        */\n        int i = 1;\n        int count = 1;\n        unordered_set<int> uSetAlreadyRemainderFound;\n        do{\n            if(i%k == 0)\n                return count;\n            if(uSetAlreadyRemainderFound.find(i%k) != uSetAlreadyRemainderFound.end())\n                return -1;\n            uSetAlreadyRemainderFound.insert(i%k);\n            i = (i%k * 10)%k + 1;\n            count++;\n        }while(1);\n        return -1;\n    }\n};\n```
['C']