Thursday, October 2, 2025

To check later palindrom what mistake i did. Earn Inte

 /*

A palindrome is a word that is the same when read left-to-right and right-to-left.  For example, “racecar” is a palindrome.

Given a string, find all of the substrings that are also palindromes.

Example input:

  "racecar"

Example output:

   [“racecar”, “aceca”, “cec”, “r”, “a”, “c”, “e”, “c”, “a”, “r”]
*/
import java.io.*;
import java.util.*;


class Solution {
  public static void main(String[] args) {

    String str = "racecar";
    ArrayList<String> resultSet = new ArrayList<String>();
   /*  
   for(int i = 0; i< str.length(); i++)
    {
       for(int j = i; j< str.length(); j++)
       {
          String subStr =str.substring(i, j+1);
          if(isPalindrome(subStr))
          {
              resultSet.add(subStr);
              System.out.println(subStr);
          }
       }
    }
    */
   int left = 0;
   int right = str.length();
   for(int i = 0; i< str.length(); i++)
   {
          int oddString = isPalindrome(str ,i,i);
          int evenString = isPalindrome(str ,i,i+1);

         
    }
   
   
  }


public static int isPalindrome(String str, int left, int right)
    {
        while(left>=0 && right < str.length() && str.charAt(left) == str.charAt(right))
        {
           
              left--;
              right ++;
               System.out.println(str.substring(left+1, right));
         
        }
       // System.out.println(str.substring(left+1, right));
        return right-left-1;
       
    }

    public static Boolean isPalindrome(String str)
    {
        int left = 0;
        int right = str.length() -1;
        for(int i = left; i< right; i++, right--)
        {
          if(str.charAt(i) != str.charAt(right))
          {
            return false;
          }
         
        }
        return true;
    }

   
}

To check later palindrom what mistake i did. Earn Inte

  /* A palindrome is a word that is the same when read left-to-right and right-to-left.  For example, “racecar” is a palindrome. Given a str...