Let's say we need to create a string out of 2 characters : A and/or B, of given length n. The occurrence of A should at least be p times of b at any given instance. Eg: n=4,p=2. Valid combination :AAAA, AAAB, AABA. Note how ABAA is not the right one. What would be the logic behind this?
My approach so far: N=8,p=2. No of B = 1 or 2. 1st 2 place should always be A. Remaining places to consider :6. When No of B : 1, we have 6 combinations. AABAAAAA, AAABAAAA, AAAABAAA, AAAAABAA, AAAAAABA,AAAAAAAB.
When no of b :2, 6c2 gives 15, but only 12 of them will fit the criteria. AABBAAAA, AAABBAAA, AABABAAA : These 3 should not be considered. How to make this generic? It can be that the entire problem can be solved without combination principles too. If so what concepts can be used? Need inputs about this being the right approach and how to take it forward. Source : question found on a coding platform.