Count Good Strings
Updated
Problem statement
There is a string of length 2N containing only character A and B.
The string is called good string if the following two conditions are satisfied:
- The number of
Aand number ofBin that string will be same and that isN, meansNnumbers ofAandNnumbers ofBwill be present in that string. - The number of
Awill be always greater than or equal to the number ofBin any prefix string of that string.
Now you are given N and you need to count the number of good strings of length 2N,
the answer may be very large so return the answer in modulo 10000.
Function
countGoodStrings(N: int) → intExamples
Example 1
N = 3return = 5
Here are the good strings of length 2N when N=3:
- "AAABBB" good
- "AABABB" good
- "AABBAB" good
- "ABAABB" good
- "ABABAB" good
"BABABA" is not a good string because the number of Bs is greater than the number of As in the prefix "BA".
Therefore, the count of good strings is 5.
Constraints
o_o
More Commvault interview questions
Similar questions at other companies
- Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Count Routes Through Four Shop TypesOpenAI · OAOpenAI interview questions
- Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
- Count Combinations Using Weights One Through KConfluent · OAConfluent interview questions
- Count Bounded Share TransactionsOptiver · OAOptiver interview questions
- Count Strictly Increasing Subsequences of Length 3IBM · OAIBM interview questions
- Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
- Replace '?' to Avoid Adjacent DuplicatesSalesforce · OASalesforce interview questions
- Count Subsequences Without Three Equal-Parity Elements in a RowGoogle · OAGoogle interview questions
- Binary Palindromic Subsequences of Length 5Citadel · OACitadel interview questions