Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Simple counting problem but can't wrap my head around it

ABCD -- Substrings of length 2 : AB, BC, CD. Similarly ABCDE and length 3 -- ABC, BCD, CDE

I see m choose n won't work -- we'll get all subsequences too

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Consider how many of the characters in the string are valid "starting characters" for the substrings you desire. For instance, in "ABCD," only "A", "B", and "C" are valid starting characters for substrings of length 2.

In general, in a string of length $n$, if you want a substring of length $m$, you can only choose the first $n - m + 1$ characters as starting characters.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.