AB
SRM 648 · 2015-01-29 · by evima
Problem Statement
You are given two
- The string has exactly N characters, each of which is either 'A' or 'B'.
- The string s has exactly K pairs (i, j) (0 <= i < j <= N-1) such that s[i] = 'A' and s[j] = 'B'.
If there exists a string that satisfies the conditions, find and return any such string. Otherwise, return an empty string.
Constraints
- N will be between 2 and 50, inclusive.
- K will be between 0 and N(N-1)/2, inclusive.
3 2 Returns: "ABB"
This string has exactly two pairs (i, j) mentioned in the statement: (0, 1) and (0, 2).
2 0 Returns: "BA"
Please note that there are valid test cases with K = 0.
5 8 Returns: ""
Five characters is too short for this value of K.
10 12 Returns: "BAABBABAAB"
Please note that this is an example of a solution; other valid solutions will also be accepted.
2 1 Returns: "AB"
Submissions are judged against all 86 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AB with a public method string createString(int N, int K) · 86 test cases · 2 s / 256 MB per case