Sign up ×
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|cite|improve this question

2 Answers 2

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|cite|improve this answer

It's the permutation topic.

1) length of main string : n

2) Select "k" number of charactered in ordered so,

Number of k-substring =

( (n!)/(n-k)! ) = (n-k+1)
number of k-substrings in given string of length n.

share|cite|improve this answer

Your Answer


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.