Hi Community,
I was giving this problem on hackerrank.
out of 15 I have passed 11 test cases. But dont know the other 4 cases where I am failing.
If any 1 can look and provide some guidence.
By the way the contest is over.


Here is my code:
public static int minimumSwaps(String status) {
int count = 0;
if(status.length() == 1 )return 0;
if(status.length() == 2 && status.charAt(0) == status.charAt(1)){return 1;}
char[] str = status.toCharArray();
for(int i=1;i<str.length-1;i++){
if(str[i]== str[i-1] && str[i] != str[i+1]){
if(str[i-1] == 'S'){
str[i-1] = 'R';
}else if(str[i-1] == 'R'){
str[i-1] = 'S'; } count++; }
else if(str[i-1] != str[i] && str[i] == str[i+1]){
if(str[i+1] == 'S'){
str[i+1] = 'R';
}
else if(str[i+1] == 'R'){
str[i+1] = 'S';
}count++;}
else if(str[i-1] == str[i] && str[i] == str[i+1]){
if(str[i] == 'R'){
str[i] = 'S';
}
else if(str[i] == 'S'){
str[i] = 'R';
} count++; } }
return count;
}
So what I am doing is I am comparing the ith element with i-1 and i+1;
if i == i-1 and not = to i+1
then increase the count to 1 and change i-1;
else if(i !=i-1 && i==i+1)then incr the count and chnge i+1
3rd case is
if i == i-1 and i+1 the I am changing the i in increase the count.