Write a function minChanges(s) that returns the smallest number of changes you need so that no two characters next to each other in the string s are equal.
s has 0 to 10000 characters. Characters are compared exactly: 'a' and 'A' are different. Any character can appear: letters, digits, spaces, punctuation like '*' or '!'.0.L needs Math.floor(L / 2) changes: in 'aaaa' you change the second and the fourth a ('abab'), so 2 changes. Add up the numbers for all runs.One loop over the string is enough: count the length of the current run and add its changes when the run ends.
minChanges('aab')Returns 1
minChanges('aaaa')Returns 2
minChanges('aabbcc')Returns 3
Asked at Cred · Source
minChanges('aab')1minChanges('aaaa')2minChanges('abc')0Hidden tests run on Submit.