From 48e88f7567aa52a61ce209ab078418801c3e5b63 Mon Sep 17 00:00:00 2001 From: Mulla Arsiya Tasleem <2400090250@kluniversity.in> Date: Tue, 25 Nov 2025 22:17:07 +0530 Subject: [PATCH] Create smallestRepunitDivByK.java --- smallestRepunitDivByK.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 smallestRepunitDivByK.java diff --git a/smallestRepunitDivByK.java b/smallestRepunitDivByK.java new file mode 100644 index 00000000..d39cc3c6 --- /dev/null +++ b/smallestRepunitDivByK.java @@ -0,0 +1,19 @@ +class Solution { + public int smallestRepunitDivByK(int k) { + if(k == 2 || k == 5) + { + return -1; + } + + int rem = 0; + for(int length = 1; length<=k; length++) + { + rem = (rem*10 + 1) % k; // simulate adding a '1' + if(rem == 0) + { + return length; + } + } + return -1; + } +}