Pergunta de entrevista da empresa Microsoft

I was asked to write an algorithm in C++ to sort an array. The function I was to write was to take in a string of letters "b" and "r". b = a red ball and r = a blue ball. The function was to return an integer with the least number of swaps needed to separate the balls to be next to their own colors... So for example, RBBR would return 1, since you only need to swap one of the letters to be RRBB or BBRR.