package leetcode;

/**
 * https://leetcode.com/problems/maximum-repeating-substring/
 */
public class Problem1668 {
    public int maxRepeating(String sequence, String word) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1668 prob = new Problem1668();
        System.out.println(prob.maxRepeating("ababc", "ab")); // 2
        System.out.println(prob.maxRepeating("ababc", "ba")); // 1
        System.out.println(prob.maxRepeating("ababc", "ac")); // 0
    }
}

@@ -181,332 +181,605 @@
     
-// TODO%0A        return 0;
+int answer = 0;%0A        int i = 0;%0A        while (i + word.length() %3C= sequence.length()) %7B
 %0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1668 prob = new Problem1668();%0A        System.out.println(prob.maxRepeating(%22ababc%22, %22ab%22)); // 2%0A        System.out.println(prob.maxRepeating(%22ababc%22, %22ba%22)); // 1%0A        System.out.println(prob.maxRepeating(%22ababc%22, %22ac%22)); // 0
+    String substring = sequence.substring(i, i + word.length());%0A            if (!substring.equals(word)) %7B%0A                i++;%0A            %7D else %7B%0A                int count = 1;%0A                i += word.length();%0A                while (i + word.length() %3C= sequence.length() && sequence.startsWith(word, i)) %7B%0A                    i += word.length();%0A                    count++;%0A                %7D%0A                answer = Math.max(answer, count);%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1668