Super Reduced String

  • + 1 comment

    My code is running everywhere and giving right output but while running test cases like **"aa" and "baab" ** fails?

    public static String superReducedString(String s) {
          // Write your code here          
              StringBuilder sb = new StringBuilder(s+"");
              int l = 0;
              while(l<=sb.length()-2){
                  if(sb.charAt(l)==sb.charAt(l+1)){
                      String temp = superReducedString(sb.delete(l, l+2).toString());
                      s = temp;
                      // return sb.toString();
                  }
                  l++;
              }
              if(s=="") return "Empty string";
              return s;
          }