I have an array of String called x that holds either "Boy" or "Girl". Then I want to create N groups without changing the order of x. Each group must have a minimum of 2 Strings, and the first member and the last member of the group MUST be the same String (both "Boy" or both "Girl"). Return the amount of ways to create the groups.
Example:
String[] x = {"Boy", "Boy", "Girl", "Boy", "Girl", "Girl", "Boy", "Boy"}; // Can be any length
int N = 3; // N <= x.length/2
groupCount(x, N); // Returns 2
Explanation:
The two possibilities to divide x into three groups are:
- ["Boy", "Boy"], ["Girl", "Boy", "Girl", "Girl"], ["Boy", "Boy"]
- ["Boy", "Boy", "Girl", "Boy"], ["Girl", "Girl"], ["Boy", "Boy"]
How do I implement groupCount? I've wrapped my head around it for a while. Thanks.