JAVA - O(K) - compute and space
If k is even or is a multiple, it will never divide a number ending in 1. So, we can immediately rule those out and return -1. \n Since    remainders at some po
If k is even or is a multiple, it will never divide a number ending in 1. So, we can immediately rule those out and return -1. \n Since    remainders at some point starts repeating, we can use that information to keep only remainders and the moment we start seeing a reminder that has already seen, we can stop and decide we will not find a number 111....1 that is divisible by k. So, we generate val * 10 + 1 with existing val. \n\nif val = k \\* factor + rem; then we can safely keep only the remainder and ignore the k\\*factor since k\\*factor % k = 0. So, we only keep track of remainders and keep a Set of remainders.. \n\n```\nclass Solution {\n    public int smallestRepunitDivByK(int k) {\n        // multiples of 2 and 5 never end with 1\n        if (k % 2 ==0 || k % 5 == 0)\n            return -1;\n        \n        Set<Integer> seen = new HashSet<>();\n        int rslt = 1, val = 0;\n        while (seen.add(val)){\n            val = (val*10 + 1) % k;\n            if (val == 0){\n                return rslt;\n            }\n            rslt++;\n        }\n        return -1;\n    }\n}\n```
[]