Skip to content

Instantly share code, notes, and snippets.

@taravancil
Created September 28, 2016 22:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
function processData(input) {
const lines = input.split('\n')
// Discard the first line
lines.shift()
for (line of lines) {
// Split line into array of chars
countMinimumDeletions(line.split(''))
}
}
function countMinimumDeletions(letters) {
let deletionCount = 0
// O(n)
for (let i = 0; i < letters.length - 1; i++) {
if (letters[i] === letters[i+1]) {
deletionCount++
}
}
return deletionCount
}

Example

Input

5 // the number of test cases to evaluate
AAAA
BBBBB
ABABABAB
BABABA
AAABBB

Expected output

3
4
0
0
4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment