i have applied the concept that if length of garland is 1 then garland is beautiful else i hae counted number of R and G and if they are equal and their sum is even and then i have counted the mismatched pair and printed the result accordingly.

Can anyone please help me to figure out whats wrong…??

@joffan is absolutely right. @rk_221b you didn’t check for the start and end joint. Even if you did it later, it isn’t correct. Here is the small modification to your code which gives AC.