Intuition
Since shift
and capslock
does not affect, that’s just a fancy way of saying the string is case in-sensitive. So this boils down the problem to detecting how many times are we changing adjacent characters in s.lower()
.
For Python devs, we use itertools.pairwise()
- this returns pairwise tuples of the entire array. Learn more about it here
Code
Python3
Python3 One Liner
Big O Analysis
-
Runtime
The runtime complexity here is since we would be visiting all characters in the string of length N.
-
Memory
The memory usage is since we are not using any extra data structure.
— A