Input
5 // the number of test cases to evaluate
AAAA
BBBBB
ABABABAB
BABABA
AAABBB
Expected output
3
4
0
0
4
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 | |
} |