It looks nice, and you got the right algorithm.
Still, there are problems:
The
const-qualifier on the two functions return-value is ignored. Didn't your compiler warn?Denoting the start of a string-slice by pointer to start of the whole string and offset into it is cumbersome and inefficient. Just give a pointer to the start of the slice.
You are playing Shlemiel The Painter with all four
strlen()-calls in your loops. The compiler might be able to hoist it four you, or it might not.If it cannot, at least those in
countSubstrings()are cheaper by some constant factor than the calls to a fixedgetCounts(), and thus don't influence your codes big-oh.
But those ingetCounts()turn the function from linear to quadratic, and thus the algorithm from quadratic to cubic.What I don't get is why you ask for the strings length at all.
Just substitute!s[n]forstrlen(s) == n.
And that was all I found.