A group of $N$ dwarves are caught by an evil Troll. As usual the Troll gives the dwarves a chance to escape if they solve a puzzle he created just for the occasion.
Tomorrow morning each dwarf will receive a glove and an hat with a different non-negative integer number. The numbers are chosen by the Troll with an unknown distribution. The dwarves will be able to see each other (they all look different thus they can recognise who is wearing which hat). They can look at the numbers on all the other dwarves' hat but they won't be able to see their own number nor to communicate in any way.
After a few minutes the dwarves are called one by one in the hall and they will have to decide to wear the glove either on their left hand or in their right hand. They cannot see the choices made by the other dwarves.
As soon as everyone has worn the glove the dwarves are lined up in ascending order by the numbers on their hats (all facing the same direction) and forced to join their hands in a long chain without crossing harms. If any hand touches any glove all the dwarves have lost their chance and will be immediately eaten by the Troll. If it is always hand-to-hand or glove-to-glove all the dwarves are set free.
Remember that all of this is happening tomorrow, so tonight the dwarves have plenty of time to think of a strategy that can save them from being eaten.
For which values of $N$ such strategy exists?
Disclaimer: I don't know the solution to this puzzle. I have found it here; there is just an hint in the comments:
A strategy works perfectly if and only if it works once and keeps working under adjacent transpositions