← November 2025 questions

NOVEMBER 2025 / INTERMEDIATE / QUESTION 1

Intergalactic Battle Winner

Archived question

Try the question in your own editor, then check your output below.

THE QUESTION

Text from the official booklet. Refer to the PDF for original mathematical notation, formatting, and linked input files. Printed samples and inputs are reproduced as published.

A historian is documenting an intergalactic battle by recording successful attacks
in a string of letters. Each attack is represented by a unique uppercase character
corresponding to the alien species that executed it (e.g., ’A’ for Antennaeters, ’B’
for Borgons).
The battle is divided into multiple smaller wars, each consisting of exactlyn consec-
utive attacks. For each small war, the winner is the alien species with the highest
number of successful attacks (highest frequency). If there is a tie within a war, the
species whose letter appears earlier in the alphabet wins.
The historian wants to determine the overall battle winner — the species that has
won the most small wars. If there is a tie, output the alphabetically earlier letter.
Input format:
First line: Two integers b (total number of attacks) and n (attacks per small war)
Second line: String s of length b, containing only uppercase letters
Constraints:
1 ≤ n ≤ b ≤ 105, b%n = 0
Output format:
A single uppercase character representing the overall winner
Sample Input:
12 4
AABBCCCCAAAB
Sample Output:
A
Question Input:
600 30
XYZZAABBCCDDEFFGGHHIIJJKKLLMMNNOOXYZZAABBCCDDEFFGGHHIIJJKKLLMMNNOOXYZ
ZAABBCCDDEFFGGHHIIJJKKLLMMNNOOXYZZAABBCCDDEFFGGHHIIJJKKLLMMNNOOXYZZAA
BBCCDDEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZBBAACCDDEEGGFFHHIIJJ
KKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTU
UVVWWXXYYZZAABBDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZAABBCCEE
FFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZAABBCCDDFFGGHHIIJJKKLLMMNNO
OPPQQRRSSTTUUVVWWXXYYZZAABBCCDDEEGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXX
YYZZAABBCCDDEEFFHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZAABBCCDDEEFFGGI
IJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZAABBCCDDEEFFGGHJJKKLLMMNNOOPPQQRRS
STTUUVVWWXXYYZZ

PRACTICE CHECK

Try your answer.

The booklet supplies 636 characters but declares 600 attacks. For this practice check, use only the first 600 characters; ignore the extra 36.

Run your program in your own editor, then paste its output below. This checks the stated output or checkpoint; it does not assess your full program. Practice attempts do not affect competition scores.

Use the question input above. Enter only the output.

Reveal worked answer

Your output

A

Split the 600 attacks into 20 groups of 30. In each group choose the highest frequency, breaking ties alphabetically. Apply the same rule to group winners.

Source: Girls in Code SEA 2025 Fall Competition, 29 November 2025. Booklet created by Emily Xu and the GIC question authors. Shared for non-commercial educational use with attribution, as permitted in the booklet.