Palindromic game
Practice
3.7 (9 votes)
Algorithms
Dynamic programming
Problem
92% Success 4068 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Alice and Bob are playing a game with a string of English alphabets (both uppercase and lowercase). They can select a character either from the start or end of the string. Put the selected character in a common box. The winner of the game is the first person who can make a string palindrome of length greater than 1 by using some of the box's characters. Alice starts first to pick a character and both players play optimally. Determine the winner of the game or depict if it is a Tie.

Note: A tie occurs when no one wins.

For example: If the string is aabc, then Alice can select the character 'a' or 'c' and store it into the box. If Alice chooses 'a', then the resulting string for Bob is abc. This helps Bob so that he can select either 'a' or 'c', so he can select 'a' and store it into box. Now, Bob can make a string 'aa' which is a palindrome of length is greater than 1. Hence, Bob wins the game.

Input format

The only line contains a string \(s\) of \(n\) lowercase and uppercase English letters. (\(1 \le |s| \le 10^5\))

Output format

If Alice wins the game, then print Alice. If Bob wins the game, then print Bob. If no one wins the game, then print Tie.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
2 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingFenwick TreeMediumSegment TreesSorting
Points:30
10 votes
Tags:
AlgorithmsDynamic ProgrammingIntroduction to Dynamic Programming 1
Points:30
4 votes
Tags:
DatastructuresAlgorithmsDynamic ProgrammingIntroduction to Dynamic Programming 1Bitmask