Sort by

recency

|

1444 Discussions

|

  • + 0 comments

    The test case 7 is wrong

    s=aaaaaaaaaa t=aaaaa k=7

    You only need 5 delete operations on s to convert t

    But the test case expect "Yes"

  • + 0 comments
    def appendAndDelete(s, t, k):
        prefix_count = 0
        len_s = len(s)
        len_t = len(t)
        while prefix_count < len(t):
            if prefix_count > (len_s - 1) or s[prefix_count] != t[prefix_count]:
                break
            else:
                prefix_count += 1
        
        delete_required = len_s - prefix_count
        addition_required = len_t - prefix_count
        total_ops_required = delete_required + addition_required
        if k >= (len_s + len_t):
            return "Yes"
            
        if k >= total_ops_required and (k - total_ops_required) % 2 == 0:
            return "Yes"
            
        return "No"
    
  • + 1 comment

    There is a testcase 5 in which we have: y yu 2 Should'nt the expected output be 'Yes'? because the operation can be performed according to me.

  • + 0 comments

    Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-append-and-delete-problem-solution.html

  • + 0 comments

    python

    def appendAndDelete(s, t, k):
        # Write your code here
        
        #all cases where the length of the two strings combined is less than or equal to k work
        if len(t) + len(s) <= k:
            return 'Yes'
        
        index=0
    		
        while True:
            
            #remove the out of index range scenario
            if index > len(s) - 1 or index > len(t) - 1:
                break
            #determine up to which index is the same
            if s[index] == t[index]:
                index+=1
            else:
                break
                
        #determine remaining steps needed and if the difference between remaining and k is either 0 or even
         
        remaining_steps = len(s) + len(t) - index * 2
        if remaining_steps <= k and (k - remaining_steps) % 2 == 0:
            return 'Yes'
        else:
            return 'No'