Ok,I think i got it.Lets say that the giant:-
CASES:-
1. picks up a white gnome,and then a red one-the red one(who dosnt know that he is red)assumes his hat can be of any color and goes behind the white gnome.
Now,lets say a 3rd gnome is picked-
-he wouldnt know the color of his hat-so he decides to be on the safer side and get right into the middle of those two gnomes,which have 1 red and other white.In this way-the 4th gnome will get in between the gnomes where he sees that the colors of the hats are changing and so will the other incoming gnomes.
2.Picks up 2 gnomes such that they are of the same colour-then the 3rd gnome sees that the 2 are of the same colour and gets behind both of them,then the 4th one sees either-
-3 white(or 3red) gnomes-then the 4th gnome will occupy the place behind them
OR
-2 white(or red) and another red(or white) gnome-and so gets into the place,where there is a difference in color between 2 gnomes and so on and so forth...
Moral of story-get right in between 2 gnomes having different colored hats and if they all have same color,then go stand last,lol
Damn,this is hard to explain,but hope you'll get my point..Also hope that this is the right answer..