I have been stuck in this problem for a couple of days now. Suppose we have $n_1$ people from group $A_1$, and $n_2$ people from group $A_2$. We want to count the number of ways to place them in a row such that a maximum of $k_1$ from group $A_1$ stand consecutively and $k_2$ from group $A_2$ stand consecutively.
The way I am trying to think about it is that if we call some one from group $A_1$ as 1, and from group $A_2$ as 2, Then we are counting the number of sequences in the form:
$1^{x_1}2^{x_2}1^{x_3}2^{x_4}...$ with $x_{2k-1} \leq k1$ and $x_{2k} \leq k2$ and also with $x_1+x_3+...=n_1$, $x_2+x_4+...=n_2$. However, I am not sure how I should go around approaching this since I don't know how many of these $x_{2k-1}$ and $x_{2k}$ exist. In other words, I don't know how many variables to solve this equation for, it could have $1$, $2$, or up to $k_1/k_2$ variables.