Happy Ladybugs
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
APRENDE HACIENDOPon a prueba tu intuición3 pasos
Happy Ladybugs
Usa los ejemplos y la explicación de la lección para comprobar tu idea.
Reflexión personal. No se envía a ningún servicio de IA.4
7
RBY_YBR
6
X_Y__X
2
__
6
B_RRBR
YES
NO
YES
YES
Caso de ejemplo — tu programa lee de stdin e imprime en stdout.
ENEste enunciado todavía está solo en inglés; la traducción al español está en camino.
Código inicial 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