Hackerrank - Solved Append and Delete using Javascript

preview_player
Показать описание
Hello Guys, Here is the Solution of Append and Delete in Hackerrank using Javascript.

#hackerranksolutions #hackerrank #hackerrankpush #javascript
Рекомендации по теме
Комментарии
Автор

correct solution is

function appendAndDelete(s, t, k) {
// Find the length of the common prefix
let commonLength = 0;
while (commonLength < s.length && commonLength < t.length && s[commonLength] === t[commonLength]) {
commonLength++;
}

// Calculate the number of deletions and additions required
let deletions = s.length - commonLength;
let additions = t.length - commonLength;

// Check if we have enough operations and if the remaining operations are feasible
let totalOperations = deletions + additions;
if (totalOperations <= k && (k - totalOperations) % 2 === 0 || k >= s.length + t.length) {
return "Yes";
} else {
return "No";
}
}

shafdfsvh
visit shbcf.ru