Given a length n, count the number of strings of length n that can be made using a, b and c with at-most one b and two cs allowed
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
String alphabets are only {a, b, c}
Length of string is n. (n>0)
Let's consider what can be the possible cases
Count of such string is: 1
Count of such string is: (n/1)=n
One 'b' can be placed at any of n positions, that's why n number of such strings
Count of such string (n/2)*2=n*(n-1)
One 'b' and one 'c' can take any of two places out of n and any of 'b' & 'c' can comes first.
Count of such string (n/3)*3=n*(n-1)*(n-2)/2
One 'b' and two 'c' can take any of three places out of n and there are 3 combinations possible between one 'b' & two 'c'.
Count of such string (n/2)=n*(n-1)/2
Two 'c' can take any two of n places.
Count of such string (n/1)=n
One 'c' can take any of one places out of n.
Example with explanation
C++ implementation
Output
need an explanation for this answer? contact us directly to get an explanation for this answer