import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.Math;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
int i=0;
int a=0;
int b=0;
int count=0 ;
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String s = scan.nextLine();
while (i <s.length()) {
a = 0;
b = 0;
if (s.charAt(i) == 'D') {
while (s.charAt(i) == 'D') {
a++;
i++;
}
while (s.charAt(i) == 'U') {
b++;
i++;
}
if (a == b)//unable to enter this block
{
++count;
System.out.println(count);
}
} else {
while (s.charAt(i) == 'U') {
b++;
i++;
}
while (s.charAt(i) == 'D') {
a++;
i++;
}
if (a == b)//unable to enter this block
{
++count;
System.out.println(count);
}
}
}
System.out.println(count);
}
}
The count value is not getting changed, I guess the reason behind it might be the flow cannot enter into if(a==b)
block. Can some one give clarification on it.
Input for above code is as below
Sample Input
8
UDDDUDUU
And the expected output is
1