Queue at the School

Practice this coding question on Coding Gurukul.

Problem statement

A school stages a queue simulation using two kinds of badges, B and G. At the end of every second, each adjacent BG pair exchanges places. All exchanges for a second are decided from the queue at the start of that second, so a participant cannot move twice within one tick. The teacher asks for the arrangement after a fixed amount of simulated time. Your task Given a queue of n badges and an integer t, apply the simultaneous BG-to-GB exchange rule for exactly t seconds. Print the final queue, preserving its length and the total number of each badge. There is no swapping for GB, BB or GG pairs. Important details Newly created BG pairs wait until the next second. When t is zero, print the original queue. A queue containing only one badge type never changes. Worked example For BBG with one second available, only the last two positions exchange. The result is BGB, not GBB; the newly created pair must wait another second.

Input format

First line: n t. Second line: a string of n B/G characters.

Output format

Print the queue after t seconds.

Constraints

1 <= n <= 50; 0 <= t <= 50.

Sample input

3 1
BBG

Sample output

BGB

Sign in to run or submit a solution in C++, Java or Python.