There is a secret sequence of buttons chosen from A, B, X, and Y.
Determine the entire sequence by asking how much of its prefix appears inside strings that you construct.
The first button of is guaranteed not to appear anywhere else in .
Implement the following function:
std::string guess_sequence(int N);
The grader calls this function once and provides the length of the secret sequence.
Your function must return exactly .
Do not implement main.
Your function may call:
int press(std::string p);
The string may contain only A, B, X, and Y, and its length must not exceed .
The function returns the length of the longest prefix of that occurs as a contiguous substring of .
You may call press at most times.
Exceeding the call limit, passing an invalid string, or returning a sequence other than results in a wrong answer.
The first character of does not occur at any other position in .
Suppose the secret sequence is .
Calling press("AB") returns , because AB, a prefix of length , occurs in the query and no longer prefix can fit in it.
Calling press("YABX") returns , because ABX, a prefix of length , occurs contiguously in the query, while ABXY does not.
The required return value from guess_sequence(5) is "ABXYY".
Sample 1
Input
ABXYY
Expected output
| # | User | Language | Solved |
|---|---|---|---|
| 1 | radek | C++ | Aug 25, 2026, 10:39 PM |
| 2 | benchmark | C++ | Aug 25, 2026, 10:43 PM |