program is successfully running on my pc but on submitting it is failing some test case but I have tried most of the test case on my pc and the program didn’t show any error.
Program not running
Your program should return wrong answer for cases when a certain character occurs more than 2 times consecutively. For e.g. take input string equal to “abbbc”, your program should return “abbc” while the correct answer is “abc”
did some changes but still failing
try this:
static String duplicateChar(String s) {
if (s.length() <= 1) {
return s;
}
String ros = duplicateChar(s.substring(1));
if (s.charAt(0) == ros.charAt(0)) {
return ros;
}
return s.charAt(0) + ros;
}