Efficient C solution for N Queens problem