Casidoofeb22

Solution by [email protected]

JavaScript

// Given a string str containing only the characters x and y, change it into a string such that there are no matching adjacent characters. You’re allowed to delete zero or more characters in the string. Find the minimum number of required deletions.

const uniqueAdjacent = (string) => {
  let deletions = 0

  for (let i=0; i < string.length; i++) {
    let current = string[i]
    let next = string[i+1]

    if (current === next) {
      deletions++
    }
  }
  return deletions
  }

let string = 'yyyyy'
let secondString = 'xxyxxy'

console.log(uniqueAdjacent(string))
console.log(uniqueAdjacent(secondString))