Javascript Solution Time O(n) and time O(n),  100% better Memory Usage
\n/**\n * @param {number} k\n * @return {number}\n */\nvar smallestRepunitDivByK = function(k) {\n    if( 1 > k > 1e6 ) return -1;\n    let val = 0;\n    for (l
```\n/**\n * @param {number} k\n * @return {number}\n */\nvar smallestRepunitDivByK = function(k) {\n    if( 1 > k > 1e6 ) return -1;\n    let val = 0;\n    for (let i = 1; i < 1e6; i++) {\n        val = (val * 10 + 1) % k;\n        if (val === 0) return i;\n    }\n    return -1;\n};\n```
['JavaScript']