Happy Ladybugs
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
4
7
RBY_YBR
6
X_Y__X
2
__
6
B_RRBR
Caso de ejemplo — tu programa lee de stdin e imprime en stdout.
Ladybugs are happy if adjacent to same color. You can move any ladybug to any empty cell (_). Determine if all can be made happy.
Rules: (1) If no empty cells, check if already all happy. (2) If empty cells exist, need at least 2 of each color (except if only one of a color, it can't be happy). Output 'YES' or 'NO'.
Example: 'RBY_YBR' → Has empty → Check counts: R=2, B=2, Y=2 → All have pairs → Can rearrange → YES
Formato de entrada
First line: g (games). For each game: first line n, second line string b of length n.
Formato de salida
For each game, output 'YES' if all ladybugs can be made happy, 'NO' otherwise.
Restricciones
1 ≤ g ≤ 100, 1 ≤ n ≤ 100