n peaple are standing

Added: 2025-09-13 07:20:47

Question Image

n peaple are standing

Answer

✏️ Edit
n = int(input().strip())
t = int(input().strip())
s = list(input().strip())

for _ in range(t):
    i = 0
    while i < n - 1:
        if s[i] == 'B' and s[i + 1] == 'G':
            s[i], s[i + 1] = s[i + 1], s[i]
            i += 2  # skip next index to enforce simultaneous swaps
        else:
            i += 1

print("".join(s))