Sort by

recency

|

1426 Discussions

|

  • + 0 comments

    Simple program using single for loop and east to understand

    def appendAndDelete(s, t, k):

    count=0
    for i,j in zip(s,t):
        if i == j:
            count+=1
        else:
            break
    mini=(len(s)-count)+(len(t)-count)
    if len(s)+len(t) <= k or (k >= mini and (k - mini) % 2 == 0):
        return "Yes"
    return "No"
    
  • + 0 comments

    Here is my O(k) c++ solution, you can watch the explanation here : https://youtu.be/8ZOmXfo6k0Y

    string appendAndDelete(string s, string t, int k) {
        if(k >= t.size() + s.size()) return "Yes";
        int same = min(t.size(), s.size());
        for(int i = 0; i< min(t.size(), s.size()); i++){
            if(s[i] != t[i]){
                same = i;
                break;
            }
        }
        k -= (s.size() - same);
        k -= (t.size() - same);
        return (k >= 0 && k%2 == 0)? "Yes":"No";
    }
    
  • + 0 comments

    My python solution:

    def appendAndDelete(s, t, k):
        # Write your code here
        equal_first_letters = 0
        while equal_first_letters < len(s) and equal_first_letters < len(t)\
        and s[equal_first_letters] == t[equal_first_letters]:
            equal_first_letters += 1
        min_moves = len(s) - equal_first_letters + len(t) - equal_first_letters
        return 'Yes' if (k >= min_moves and (k - min_moves) % 2 == 0) or k > len(s) + len(t) else 'No'
    
  • + 0 comments

    Whoever wrote it wrote it very well.

  • + 0 comments

    TestCase 7 is not correct there should be K = 2 instead of K= 20