Super Reduced String
Published in
1 min readDec 4, 2016
Problem Statement
Refer to the problem statement given @ Hackerrank Super Reduced String
Code
This problem is solved through Recursion but I will be working on a better solution soon. However this code pass all the Hackerrank test cases.
import java.io.*;
import java.util.*;public class Solution {public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String testString = scan.next();
System.out.println(superReduced(testString));
}
private static String superReduced(String s){
if(s.length() < 1){
return "Empty String";
}
if(s.length() == 1){
return s;
}
for(int i = 0; i < s.length(); i++){
if(i < s.length()-1 && s.charAt(i+1) == s.charAt(i)){
return superReduced(s.substring(0,i)+s.substring(i+2, s.length()));
}
}
return s;
}
}