We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Strings
  4. Super Reduced String
  5. Discussions

Super Reduced String

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • lashkarimeyjind
    2 months ago+ 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;
          }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy