How to solve the Queue ordering puzzle
Queue is an ordering puzzle built on a real theorem from combinatorics. You are given a line of children of different heights and two limits: one for the longest rising run and one for the longest falling run. Your job is to rearrange the line by swapping pairs so that nobody can pick out a rising run longer than the first limit or a falling run longer than the second. The runs do not have to be adjacent, which is what makes the puzzle genuinely hard. This guide explains the rules, the controls, the mathematics behind the puzzle, and the strategy that leads to a clean solution.

Rules and objective
You see a row of children drawn as bars of different heights. Each child has a number. Two limits are displayed: a maximum allowed length for any rising subsequence and a maximum allowed length for any falling subsequence. A rising subsequence is any set of children, taken left to right along the line, whose heights go up. They do not have to stand next to each other. Any children selected in order from left to right count, as long as each one is taller than the previous.
A falling subsequence works the same way but in the downward direction. You need both limits satisfied at the same time. The longest rising run must be at or below the first limit, and the longest falling run must be at or below the second. The puzzle is solved the moment both conditions are met.
Controls and how to play
Tap one child to select them, then tap another to swap their places. Tapping the same child a second time deselects them. The number of swaps is tracked and displayed as your score, with fewer being better. Two counters show the current longest rising run and the current longest falling run, each compared against its limit. A counter turns green when it meets the limit and stays highlighted when it does not.
The Class selector offers three sizes. Small uses a two by three limit, giving six children. Medium is the default at three by three, giving nine children. Large raises the limits to three by four, giving twelve. Press New game at any time to get a fresh scrambled line at the selected size.
The mathematics behind the puzzle
The puzzle is based on a result proved by Paul Erdos and George Szekeres in 1935. Their theorem says that any sequence of more than the product of the two limits must contain either a rising run past the first limit or a falling run past the second. The bound is exact: with exactly that many elements, it can always be arranged to avoid both, and with one more element it never can.
Every queue in this puzzle sits right at that boundary. If the limits are three rising and three falling, you get nine children, which is three times three. With ten children it would be impossible no matter how you shuffled them. That is not a difficulty setting but a mathematical fact, which is what the tagline on the page means. The result is usually seen as the starting point of Ramsey theory in geometry, and the original question that prompted it was asked by Esther Klein, who later married Szekeres. Erdos called it the happy ending problem for that reason.
The block strategy
The arrangement that always works has a clean structure. Divide the children into blocks. The number of blocks should equal the rising limit, and the size of each block should equal the falling limit. Inside each block, arrange the children in descending order. Then make sure the blocks themselves go in ascending order, meaning the tallest child in the first block is shorter than the shortest child in the second block.
Why does this work? A rising run can take at most one child from each block, because within a block the heights fall. So the longest rising run is at most the number of blocks, which equals the rising limit. A falling run can never leave the block it starts in, because moving to the next block would mean jumping to a taller child. So the longest falling run is at most the size of one block, which equals the falling limit.
Fixing the worse number first
When you start swapping, look at the two counters. Whichever limit is further over is the one to attack first. If the longest rising run is five against a limit of three but the longest falling run is only four against a limit of three, focus on breaking up the rising run. The two limits fight each other. Breaking a long rising run tends to build a long falling one, because pulling a tall child out of a rising sequence often drops it into the middle of a descending stretch.
The key insight is that you are not looking for any arrangement that meets both limits. You are looking for the block arrangement described above, because it is the only structure that guarantees both limits are met. Every swap should move the line closer to that block pattern. If a swap fixes one counter but makes the other worse by the same amount, it was not progress.
Working out the blocks by hand
With nine children numbered one through nine and limits of three and three, the target arrangement is: 3, 2, 1, 6, 5, 4, 9, 8, 7. The first block is three, two, one, which is descending. The second block is six, five, four. The third is nine, eight, seven. The blocks themselves rise because three is less than four and six is less than seven.
On the Large setting with twelve children and limits of three rising and four falling, you need three blocks of four: 4, 3, 2, 1, 8, 7, 6, 5, 12, 11, 10, 9. Each block has four children in descending order, and the blocks ascend. Knowing the target before you start swapping saves a lot of trial and error, because every swap can be planned to move one child toward its correct position in the target.
Common mistakes beginners make
The most common mistake is treating the runs as adjacent. Beginners swap two neighbours and expect the longest run to drop, but the longest run might be spread across the entire line. Moving child five from position two to position eight does nothing if the rising run passes through positions one, four, six, and nine. You need to think about which children are part of the long run and move one of them to a place where it no longer extends the sequence.
Another error is swapping randomly until both counters happen to go green. On the Small size this can sometimes work by luck, but on Medium and Large the number of possible arrangements is enormous and random swapping almost never lands on a valid one. The block method is far more reliable.
Some beginners also focus entirely on one counter while ignoring the other. They rearrange the line to kill every long rising run and end up with a perfectly descending sequence, which is the longest possible falling run. Both limits must be met at the same time, and the block structure is the only way to guarantee that.
Difficulty levels in detail
Small uses limits of two rising and three falling, giving six children in two blocks of three. This is the gentlest introduction because there are only six items to arrange. Medium uses three rising and three falling with nine children, which is the setting where the puzzle has enough depth to be interesting. Large uses three rising and four falling with twelve children and is the hardest setting, not because the block structure is different but because finding the right swaps takes more careful counting.
On all levels, lower swap counts are better. The game tracks your best score across sessions in local storage. Aiming for the minimum number of swaps is a separate challenge once you can solve the puzzle reliably.
Privacy and how the puzzle runs
The entire puzzle runs inside your browser. No data is sent to a server, there is no account to create, and your best score is stored in local storage on this device only. It will not follow you to another machine or another browser on the same machine. Once the page has loaded, the game works fully offline, so you can work through puzzles anywhere without a connection.
