In [19]:
def getMinDeletionsDp(a):
    n = len(a)
    deletions = [0 for i in range(n)]
    
    for i in range(1, n):
        for j in range(i, 0, -1):
            if a[j] == a[j-1]:
                deletions[i] = deletions[i] + 1
    print(deletions)
    return deletions[len(a)-1]

In [29]:
def getMinDeletions(a):
    deletions = 0
    for i in range(len(a)-1):
        if a[i] == a[i+1]:
            deletions = deletions + 1
    return deletions

In [30]:
#3
#4
#0
#0
#4
sample = "ABAA"
a = "AAAA"
b = "BBBBB"
c = "ABABABAB"
d = "BABABA"
e = "AAABBB"
answers = {a:3,b:4,c:0,d:0,e:4}
result = getMinDeletions(e)
print(result,result==answers[e])


4 True

In [ ]: