// Main method for CodeHS autograder public static void main(String[] args) { // Test cases System.out.println(countOccurrences("Hello hello HELLO", "hello")); // Should print 3 System.out.println(countOccurrences("This is a test. This is only a test.", "test")); // Should print 2 System.out.println(countOccurrences("No matches here.", "xyz")); // Should print 0 }
def count_occurrences(message, keyword): lower_message = message.lower() lower_keyword = keyword.lower() count = 0 start = 0 4.2.5 text messages codehs github
If the keyword is "aa" and the message is "aaa" , moving by keyword length ensures we don't double-count overlapping matches. Most CodeHS versions do not count overlaps (e.g., "aaa" with keyword "aa" counts once, not twice). If your assignment requires overlaps, you would advance by 1 instead of keyword.length() . // Main method for CodeHS autograder public static