We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
stringappendAndDelete(strings,stringt,intk){if(k>=(s.length()+t.length()))return"Yes";inti=0;intsz=min(s.length(),t.length());// longest same prefixfor(;i<sz;i++){if(s[i]!=t[i]){break;}}intn=s.length();intm=t.length();intdeleteOpe=n-i;intaddOpe=max(0,m-i);inttotOpe=deleteOpe+addOpe;// why the k-totOpe % 2 == 0? because must be EXACTLY k operations.if(k>=totOpe&&(k-totOpe)%2==0){return"Yes";}return"No";}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Append and Delete
You are viewing a single comment's thread. Return to all comments →
Simple C++ solution with the concepts involucred.