Sort by

recency

|

1443 Discussions

|

  • + 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"
    
  • + 0 comments

    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'
    
  • + 0 comments
    fn appendAndDelete(s: &str, t: &str, k: i32) -> String {
        let s_len = s.len() as i32;
        let t_len = t.len() as i32;
        let common_len = s.chars().zip(t.chars()).take_while(|a| a.0 == a.1).count() as i32;
        let min_operations = (s_len - common_len) + (t_len - common_len);
    
        if min_operations > k {
            return "No".into();
        } else if (k - min_operations) % 2 == 0 {
            return "Yes".into();
        } else if k >= s_len + t_len {
            return "Yes".into();
        } else {
            return "No".into();
        }
    }