Solution using memoization of remainders
We can simply memonize the remainders and check to see if we already have got this remainder. If we have already got this remainder, this means that we are stuc
We can simply memonize the remainders and check to see if we already have got this remainder. If we have already got this remainder, this means that we are stuck in infinte loop, so break out and return -1;\n\n```\nclass Solution {\npublic:\n    bool dp[100005];\n    int smallestRepunitDivByK(int K) {\n        memset(dp,0,sizeof(dp));\n        int len =1;\n        int last_rem=0;\n        \n        \n        while(true)\n        {\n            last_rem =(last_rem*10 + 1)%K;\n            if(last_rem==0)\n                return len;\n            if(dp[last_rem])\n                break;\n            dp[last_rem]=1;\n            len++;\n        }\n        return -1;\n    }\n};\n```
['Memoization', 'C++']