JAVA | Two solutions
Please Upvote !!! (\u25E0\u203F\u25E0)\n\nclass Solution {\n    public int smallestRepunitDivByK(int k) {\n        if (k % 2 == 0 || k % 5 == 0) return -1;\n   
### ***Please Upvote !!!*** **(\u25E0\u203F\u25E0)**\n```\nclass Solution {\n    public int smallestRepunitDivByK(int k) {\n        if (k % 2 == 0 || k % 5 == 0) return -1;\n        int n = 1, len = 1;\n\n        while (n % k != 0) {\n            n = (n * 10 + 1) % k;\n            len++;\n        }\n\n        return len;\n    }\n}\n\n// TC: O(k)\n```\n#### OR\n```\nclass Solution {\n    public int smallestRepunitDivByK(int k) {\n        if (k % 2 == 0 || k % 5 == 0) return -1;\n        int rem = 0;\n\n        for (int len = 1; len <= k; len++) {\n            rem = (rem * 10 + 1) % k;\n            if (rem == 0) return len;\n        }\n\n        return -1;\n    }\n}\n\n// O(k)\n```
['Java']