for this question, I didnt know we had to think about the position of each character so I just used Counter. But if we have like "ere", if we use counter it gives us wrong ans of 2 but actually answer is 1. So we have to just find the consecutive duplicate characters, which by doing so we are considering the order (consecutive characters)
from collections import Counter
class Solution:
def possibleStringCount(self, word: str) -> int:
counter = Counter(word)
ans=1
for key,val in counter.items():
if val>1:
ans+=val-1
return ans
key is u press one key at most once. So i got it this time ez
class Solution:
def possibleStringCount(self, word: str) -> int:
ans=1
tmp=""
tmp_count=1
for c in word:
if tmp!=c:
tmp=c
else:
tmp_count+=1
if tmp_count>1:
ans+=1
return ans
n time 1 space