• + 0 comments

    TS Solution -- optimal time complexity but not optimised:

    function appendAndDelete(s: string, t: string, k: number): string { // Write your code here

    for(let i = 0; i < Math.max(s.length, t.length); i++) {
    
        if(s[i] != t[i]) {
    
            let numCharsToDelete:number = s.length - i
            let numCharsToRebuild:number = t.length - i
            let minActionsToZeroAndBack:number = (s.length - numCharsToDelete) * 2
    
            k -= numCharsToDelete + numCharsToRebuild
    
            if (k >= 0 && (k % 2 === 0 || minActionsToZeroAndBack <= k )) {
                return "Yes"
            } else {
                return "No"
            }
        }
    }
    
    return "Yes" 
    

    }