Here is the details about the question:
Given set {a, b, c, d, e}
if n =1, output will be 5 because, substrings of length 1 are {a, b, c, d, e}
if n =2, output will be 15(5+4+3+2+1) because, substrings of length 2 are
{aa,ab,ac,ad,ae,
bb,bc,bd,be
cc,cd,ce,
dd,de,
ee}
If n=3, output = 35 (15+10+6+3+1)
if n=4, output =70 (35+20+10+4+1)
In my approach to this solution was initializing an array of size 5 with 1s and loop for i=2 to n times.
in each loop, array[0] = sum of all elements in the array, array[1]= sum of elements from 1 to the end and so on.
Any other approach or logic please?
Note: It is not direct combination problem(5C2 for n=2) because we are considering aa,bb,cc,dd,ee strings as well, while in typical combination we consider combination of distint elements only.