My issue
I am initially trying to find two different characters and then concatenating them with a string. Then for the rest of the characters, I am finding such substrings of length three with three different consecutive characters. This way we can ensure that there are no palindromic substrings in the string. But my code is failing a hidden testcase? Kindly help me in solving the problem.
My code
import random
import string
t = int(input())
for _ in range(t):
n = int(input())
ch1 = random.choice(string.ascii_lowercase)
ch2 = random.choice(string.ascii_lowercase)
while(ch1==ch2):
ch1 = random.choice(string.ascii_lowercase)
st = ch1 + ch2
for i in range(2,n):
ch = random.choice(string.ascii_lowercase)
while(ch in st[i-2:i]):
ch = random.choice(string.ascii_lowercase)
st = st + ch
print(st)
Problem Link: Palindromes Not Allowed Practice Coding Problem - CodeChef