Count valid length-N strings over {a,b,c,d} with no adjacent-order neighbors and an odd number of 'a's.
Unlock detailed company stats for this questionUpgrade
Given an alphabet set S = {'a','b','c','d'} and an integer N, find the total number of valid strings of length N. The characters are ordered as {a, b, c, d} with index(a)=0, index(b)=1, index(c)=2, index(d)=3. For every adjacent pair (x, y) in the string, |index(x) - index(y)| must not equal 1, so the forbidden adjacent pairs are ab, ba, bc, cb, cd, dc and all other pairs are allowed. The total number of occurrences of 'a' in the string must be odd. Return the answer modulo 10^9+7.
Input: a single integer N (1 <= N <= 10^5). Output: a single integer, the number of valid strings modulo 10^9+7.
Examples: N=1 -> 1 (a); N=2 -> 4 (ac, ad, ca, da); N=3 -> 11; N=4 -> 29.
Format · Online assessment.
Community answers
No answers contributed by the community yet.
Related courses

Course

Course
Course
