• + 0 comments

    My JAVA Solution:

    public static String appendAndDelete(String s, String t, int k) {
        // Write your code here
            int length_s = s.length();
            int length_t = t.length();
            if(k >= length_s + length_t) return "Yes";
            else{
                int differenciator = 0;
                int min_operations = 0;
                
                for (int i = 0; i < (length_s>=length_t?length_t:length_s); i++) {
                    if(s.charAt(i) == t.charAt(i)) differenciator++;
                    else break;
                }
                
                min_operations = (length_s - differenciator) + (length_t - differenciator);
                
                if(k < min_operations) return "No";
                else if(k == min_operations) return "Yes";
                else{
                    if(min_operations%2 == 0){
                        if(k%2 == 0) return "Yes";
                        else return "No";
                    }
                    else{
                        if(k%2 != 0) return "Yes";
                        else return "No";
                    }
                }
            }
        }