title: Check if string is a palindrome after removing one character. My working solution is too slow
body: <p>I cant seem to find a proper solution to an exercise. The exercise asks to create a method that returns true if a string can be a palindrome by removing one character. I have a solution that works but fails tests of large (100,000 character) strings because its exceeding the time limit of 1 second. Can somebody point me in the right direction?</p>
  
  <p>I realize my approach is brute force and I'm sure there's a better way to solve it. I'm assuming my problem lies with the iteration.</p>
  
  <pre><code>public class Main {
  
      public static boolean makePalindrome(String mjono) {
  
          StringBuilder sb = new StringBuilder(mjono);
  
  
          for (int i = 0; i &lt; mjono.length(); i++) {
              sb.deleteCharAt(i);
  
              if(isPalindrome(sb.toString())){
                  return true;
              } else {
                  sb.insert(i, mjono.charAt(i));
              }
          }
          return false;
      }
  
      private static boolean isPalindrome(String string) {
          return string.equals(new StringBuilder(string).reverse().toString());
      }
  
      public static void main(String[] args) {
          System.out.println(makePalindrome("ABCBXA"));
          System.out.println(makePalindrome("ABCBAX"));
          System.out.println(makePalindrome("ABCXBA"));
          System.out.println(makePalindrome("ABCDE"));
          System.out.println(makePalindrome("BAAAAC"));
      }
  }
  </code></pre>
  
  <p>These are the tests it fails:</p>
  
  <pre><code>@Test(timeout=1000)
  public void suuri2() {
      int n = 100000;
      char[] t = new char[n];
      for (int i = 0; i &lt; n; i++) t[i] = 'A';
      t[12345] = 'B';
      testaaSuuri(new String(t), true);
  }
  
  @Test(timeout=1000)
  public void suuri3() {
      int n = 100000;
      char[] t = new char[n];
      for (int i = 0; i &lt; n; i++) t[i] = 'A';
      t[12345] = 'B';
      t[54321] = 'C';
      testaaSuuri(new String(t), false);
  }
  </code></pre>
  
  <p>Thanks in advance.</p>