Software Development

Remodel the given String into two identical Strings by eradicating at most one character

Remodel the given String into two identical Strings by eradicating at most one character
Written by admin


  

import java.io.*;

import java.math.*;

import java.util.*;

public class GFG {

  

    

    

    

    public static boolean test(String a, String b)

    {

        int l = 0;

        int okay = 0;

        int countdiff = 0;

        whereas (l < a.size()) {

            if (okay < b.size()

                && a.charAt(l) == b.charAt(okay)) {

                l++;

                okay++;

            }

            else {

                l++;

                countdiff++;

            }

        }

        return countdiff <= 1;

    }

  

    

    public static void primary(String args[])

    {

  

        

        int N = 5;

  

        

        String s = "ababz";

  

        

        if (s.size() == 1) {

            System.out.println("NO");

        }

  

        

        else if (s.size() % 2 == 0) {

  

            

            String fir = s.substring(0, (s.size() / 2));

  

            

            String sec = s.substring((s.size() / 2));

  

            

            

            if (fir.equals(sec)) {

                System.out.println("YES");

            }

  

            

            else {

                System.out.println("NO");

            }

        }

  

        

        else {

  

            

            

            String fir = s.substring(0, s.size() / 2 + 1);

            String sec = s.substring(s.size() / 2 + 1);

            String third = s.substring(s.size() / 2);

            String fourth = s.substring(0, s.size() / 2);

  

            

            

            

            if (test(fir, sec) || test(third, fourth)) {

                System.out.println("YES");

            }

            else {

                System.out.println("NO");

            }

        }

    }

}

About the author

admin

Leave a Comment