Solution for NQueens problem