Mentalist Solution Decode Nerds Codechef 2021
SOLUTION
” CLICK HERE “
Patrick Jane and Dumar Tanner are playing a game … turns. The game consists of a special clock which consists of numbers- and . The needle of the clock starts from and moves in clockwise direction every 1 minute. When the clock strikes its Patrick Jane's turn, else it is Tanner's turn to play. The game starts with all game pieces arranged in a single row. The game pieces consists of alphabets (a-z). Each alphabet holds a value, with having having …. having a value of .
In each turn, a player chooses either the first or last piece from the row. After selecting the piece, the player acquires its value. In every game, Jane and Tanner plays, Jane acquires the game pieces which sum up to greater/equal value than Tanner.
Given a string of game pieces, find the maximum score Jane acquires in each game.
Input:
- A single line consisting of string.
Output:
An integer representing the maximum score of Jane.
Sample Input 0:
slxt
Sample Output 0:
22
Sample Input 1:
yyyy
Sample Output 1:
4
EXPLANATION:
When clock strikes 1 for the first time, Jane picks 't'.When clock strikes 0, Tumar picks 's'. In his next turn, Jane picks 'l' and Tumar is left with 'x'.
Jane's collection - 't', 'l' Value of Jane's collection :- 7 + 15 = 22
Tumar's collection - 's', 'x' Value of Tumar's collection :- 8 + 3 = 11

Social Plugin