Skip to content

Instantly share code, notes, and snippets.

@taravancil
Created September 28, 2016 22:51
Show Gist options
  • Save taravancil/a70a1ec2df9025c53a1001477d947173 to your computer and use it in GitHub Desktop.
Save taravancil/a70a1ec2df9025c53a1001477d947173 to your computer and use it in GitHub Desktop.
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