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) {
// Write your code here
int n = s.length();
int m = t.length();
int i = 0;
char[] a = s.toCharArray();
char[] b = t.toCharArray();
while (i < n && i < m && a[i] == b[i]) {
i++;
}
int opsNeeded = (n - i) + (m - i);
if (opsNeeded > k) {
return "No";
}
else if ((k - opsNeeded) % 2 == 0 || k >= n + m) {
return "Yes";
}
else {
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 →
Java ::
public static String appendAndDelete(String s, String t, int k) { // Write your code here int n = s.length(); int m = t.length(); int i = 0; char[] a = s.toCharArray();