Easy30 pts
Happy Ladybugs
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
Input
First line: g (games). For each game: first line n, second line string b of length n.
Output
For each game, output 'YES' if all ladybugs can be made happy, 'NO' otherwise.
Sample
4 7 RBY_YBR 6 X_Y__X 2 __ 6 B_RRBR
Expected
YES NO YES YES
Loading editor…
Output
No output yet. Run your code to see results.