My issue
Not able to solve
My code
def suspense_string(s):
alice_turn = True
alice_str = ""
bob_str = ""
while s:
if alice_turn:
# Alice's turn: Choose the lexicographically smaller character
if s[0] <= s[-1]:
alice_str += s[0]
s = s[1:]
else:
alice_str += s[-1]
s = s[:-1]
else:
# Bob's turn: Choose the lexicographically larger character
if s[0] <= s[-1]:
bob_str += s[0]
s = s[1:]
else:
bob_str += s[-1]
s = s[:-1]
alice_turn = not alice_turn
return alice_str + bob_str[::-1]
# Input reading and processing
t = int(input("Enter the number of test cases: "))
for _ in range(t):
n = int(input())
binary_string = input().strip()
resultant_string = suspense_string(binary_string)
print(resultant_string)
Learning course: Stacks and Queues
Problem Link: Suspense String Practice Problem in Stacks and Queues - CodeChef