A faster approach could be based around the idea of counting "valid" substrings 
ending at each position in the string (here I say "valid" to mean containing at 
least n consecutive consonants).

For a given position e, either there are no valid substrings ending at e, or 
there is a position s_0 such that all substrings [s,e] with s <= s_0 are valid, 
and all other substrings ending at e are not.  If you know s_0 then the number 
of valid [s, e] is easy to count.

By keeping a running count of consecutive consonants, you can keep track of s_0 
as you increase e, giving a linear time algorithm.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-code/-/vUdvyd6bdOcJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to