Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions Problem Solving/Python/AlternatingCharacters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#You are given a string containing characters A and B only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string.

#Your task is to find the minimum number of required deletions.

#For example, given the string s=AABAAB, remove an A at positions 0 and 3 to make s=ABAB in 2 deletions.

#Function Description

#Complete the alternatingCharacters function in the editor below. It must return an integer representing the minimum number of deletions to make the alternating string.

#alternatingCharacters has the following parameter(s):
#s: a string

#Input Format

#The first line contains an integer q, the number of queries.
#The next q lines each contain a string s.

#Constraints
#1<=q<=10
#1<=|s|<=10^5
#Each string will consist only of characters A and B

#Output Format
#For each query, print the minimum number of deletions required on a new line.

#Sample Input
#5
#AAAA
#BBBBB
#ABABABAB
#BABABA
#AAABBB

#Sample Output
#3
#4
#0
#0
#4

#!/bin/python3

import os

# Complete the alternatingCharacters function below.
def alternatingCharacters(s):
l=[]
ct=0
for ch in s:
l.append(ch)
a=[]
a=l
length= len(l)
for i in range(length):
for j in range(i+1, len(l)):
if(l[i] == l[j]):
a[j]=0
else:
break
for i in a:
if(i==0):
ct+=1
return ct
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

q = int(input())

for q_itr in range(q):
s = input()

result = alternatingCharacters(s)

fptr.write(str(result) + '\n')

fptr.close()
2 changes: 1 addition & 1 deletion Python/TriangleQuest2.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

for i in range(1,int(input())+1):
print(([1,11,111,1111,11111,111111,1111111,11111111,111111111,1111111111][i-1])**2)
=======

for i in range(1,int(input())+1):
print(([1,11,111,1111,11111,111111,1111111,11111111,111111111,1111111111][i-1])**2)