Initialize dp array , where dp [ i ] [ j ] stores the number of alternating strings starts with i and having j elements .
var dp = new Array ( 2 ) ; dp [ 0 ] = Array ( N ) . fill ( 0 ) ; dp [ 1 ] = Array ( N ) . fill ( 0 ) ; var i ;