Sort by

recency

|

1438 Discussions

|

  • + 1 comment

    Test-3 s = "zzzzz" t = "zzzzzzz" k = 4 , how come the answer should be "Yes"? I mean how it is possible to convert s into t with exactly 4 operations? That is if we perform two append-operations and two delete-operations, with 4 operations the strings won't be same. On the otherhand if we perform four append-operations and two delete-operations the strings will be same but number of operations > k, Thus, probably the test is not correct.

  • + 0 comments

    Java solution: public static String appendAndDelete(String s, String t, int k) {

    int stringSLength = s.length();
    int stringTLength = t.length();
    int difference = Math.abs(stringSLength - stringTLength);
    
    if(t.charAt(0) != s.charAt(0)){
        if(stringSLength + stringTLength <= k){
            return "Yes";
        }
        else{
            return "No";
        }
    }
    else{
    
        if(difference == 0 && !s.equals(t)){
            for(int i = 0; i < stringSLength; i++){
                if (s.charAt(stringSLength - 1 - i) != t.charAt(stringTLength - 1 - i)) {
                    difference = i;
                    break;
                }
            }
        }
    
        if(difference <= k){
            if(difference % 2 != 0 && k % 2 == 0){
                return "No";
            }
    
            return "Yes";
        }
        else{
            return "No";
    
        }
    }
    

    }

  • + 0 comments

    I think the tests are broken

  • + 0 comments

    why s=y t="yu " or t="yu" k=2 should return "NO" in the 5th test case ?

  • + 0 comments

    Task is totally wrong. You always can delete original string and then infinitely delete emty string. Result always should be "Yes".