CodeJam Practice

Question link :

Somebody please explain me what they mean by in the problem statement

’ The contestant wins the game if their last word is the last of an alphabetically sorted list of all of the possible last words that could have been produced. ’

Explain it with the example of a testcase from the problem itself.
Thanks in advance.

1 Like

Suppose, ABC is input, you have to write input letter by letter so, first you will write A and then you have to add B, you can add B either on left side of A(i.e., BA) or on right side of A(i.e., AB), then you have to add C which can be added as following either left of BA(i.e., CBA), right of BA(i.e., BAC), left of AB(i.e., CAB) or right of AB(i.e., ABC). Out of all these combinations(CBA, BAC, CAB, ABC), CBA is the last word in alphabetically sorted list of all the possible combinations.

1 Like

Thanks @srd091

1 Like