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.
Along the lines of what was previously mentioned ...
---> note prefixLen contains the length of the matching prefix in both strings
int minOps=(schar.length-prefixLen)+(tchar.length-prefixLen);
if (k>=minOps) {
// check if you have sufficient operations to
// remove first string entirely and the replace it
// with the second string
if (k>=(schar.length+tchar.length))
System.out.println("Yes");
else {
// cannot replace first string totally so extra available
// ops must be an even multiple allowing you to
// replace portions of the prefix that both strings have
// in common
if ((k-minOps)%2==0) System.out.println("Yes");
else System.out.println("No");
}
} else {
System.out.println("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 →
Along the lines of what was previously mentioned ...
---> note prefixLen contains the length of the matching prefix in both strings