Skip to content

Feature Request: Add patternCount function (count overlapping substring occurrences using KMP) #72

Description

@MariamEwas

Summary

I would like to propose a new utility function patternCount that returns the number of times a substring (pattern) occurs in a string, including overlapping occurrences.

Motivation

Currently, there is no built-in helper for counting overlapping matches efficiently.
A naïve implementation runs in O(n·m), which may be slow for large inputs.
By using the Knuth–Morris–Pratt (KMP) algorithm, we can achieve O(n + m) time complexity.

Example Usage

patternCount("aaaa", "aa"); // 3 (overlapping)
patternCount("abababa", "aba"); // 3
patternCount("hello world", "o"); // 2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Level 2Medium Level issuegssoc25GSSOC'25 approved issue

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions