appendAndDelete.js

    0

    0

    In the code above, the function appendAndDelete() takes three arguments: a string s, a string t, and a number k. It divides s into pieces using the split() function, and does the same for t. Then, it calculates the number of characters in each string, and stores that number in count. The function then loops through sArr and tArr, comparing each character in s to t. If they're the same, count++ is executed. The function then loops through sMinusCount and tMinusCount, subtracting sMinusCount from tMinusCount, and storing that value in STK. If tMinusCount + sMinusCount <= k, the function returns "Yes"; otherwise, it returns "No".

    function appendAndDelete(s, t, k) {
      let sArr = s.split("")
      let tArr = t.split("")
      let count = 0
      for (let i = 0; i === count && i < s.length; i++) {
        if (sArr[i] === tArr[i]) {
          count++
        }
      }
    
      let tMinusCount = t.length - count
      let sMinusCount = s.length - count
    
      let STK = k - (tMinusCount + sMinusCount)
    
      if (tMinusCount + sMinusCount < k && t.length + s.length > k && STK % 2 !== 0) {
        return "No"
      } else if (tMinusCount + sMinusCount <= k) {
        return "Yes"
      } else {
        return "No"
      }
    
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.