Samsung delhi Oa 3 hour question
Anonymous User
25

There is a knot in the middle of necklace of n beads at the left and the right. The red and the blue beads are randomly strung into it. You want to make the number of red and the blue beads equal by removing some of them
. As there is a knot in the middle, you cannot remove the beads passing the knot. You can remove the only from each end of the necklace. You are required to print minimum number of beads you should remove to make number of remaining red and the blue beads equal same. Although removing all beads from the necklace will always make the number of both colors equal to zero. They are a way to remove a small number of beads.
given integer N and a string A whose length is 2N
the knot is in the middle of 2N length
examples:

N=6,
A=RBBRRRBRRBRB
answer is 6

removing total of 6 beads, one from the left and five from the right, will leave three beads of each color

N=2
A=RBRB
answer is 0

N=3
A=RRRRRR
answer is 6

Comments (1)