NPS-INR-Codewars-2022

The 2022 edition of the NPS Indiranagar interhouse Cyber Programming contest.

View on GitHub

Garlanding in the FIFA Mars Cup

Problem Statement:

In order to commemorate the opening ceremony of the FIFA Mars Cup, the organisers decide to give every player a garland of red and green flowers. The organisers of the FIFA Mars Cup want to make sure that all the garlands that they give to the players are beautiful. There are T garlands each consisting of N flowers placed in a cyclic order. Since Martians believe in change, a garland is considered beautiful if no two adjacent flowers are of the same color. To make the garland beautiful you may perform the following operation at most K times:

For each garland your task is to find whether you can make a beautiful garland.

Constraints:

Subtask 1: 50 points

Subtask 2: 50 points

Input Format:

Output Format:

Sample input:

3
2 1000000000
RG
4 1
RRGG
2 1
RR

Sample output:

YES
YES
NO

Solution:

# Loop through all testcases
for _ in range(int(input())):
	# Take input and print sum
	n, k = map(int, input().split())
	s = input()

	r = s.count('R')
	g = s.count('G')

	if r != g:
		print('NO')
		continue

	if k == int(1e9):
		print('YES')
		continue

	a = 0
	b = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			if s[i] == 'R':
				a += 1
			else:
				b += 1
	
	if a == 1 and b == 1:
		print('YES')
	else:
		print('NO')