Lineup
InterviewTime limit1sMemory limit1024 MB
Given how many taller children stand to each child's left and right, find the one lineup that matches all the slips for up to 8 children.
- Level
Easy3 of 10
- Topics
- Backtracking, Brute force
- Solved
- No attempts yet
Problem
A group of n children, which we will call A, B, C, and so on, decides to test your reasoning. Without you watching, they line up in a row. Then each child counts how many taller children are to their left, and does the same for the children to their right. After leaving the lineup, each child writes these two counts on a slip of paper and hands it to you. Their simple request is that you tell them the order in which they stood.
Here is an example with five children, shown in the figure. A has one taller child (D) to the left and two (C and E) to the right. B has three taller children to the left and one to the right. C has one taller child to the left and none to the right, and so on. The information on the slips can be summarized like this:

You did not solve the puzzle, so you sneak away and write a computer program that solves it. To make things easier the next time the children challenge you, you want to vary both the number of children (between 3 and 8, inclusive) and the information on the slips. You may assume that all children have different heights and that they made no mistakes when writing the slips. Interestingly, there is never more than one solution.
Input
The first line contains an integer (), the number of children. The next lines each contain two integers: the number of taller children to the left of the child, and the number of taller children to the right of the child.
Output
Print one line of characters that describes the lineup, as a rearrangement of the letters A, B, C, and so on.