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.
public static String appendAndDelete(String s, String t, int k) {
int numMoves = s.length() + t.length();
for (int i = 0; i < s.length() && i < t.length() && s.charAt(i) == t.charAt(i); i++) {
numMoves -= 2;
} //see which letters they have in common
if (numMoves > k || (t.length() > s.length() && (numMoves % 2 != 0))) {
return "No"; //if more than k moves are required to achieve the string
}
return "Yes";
}
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 →
My Java 8 solution: