private boolean check(final int row, final int[] columnForRow) {
        // have to check if the new placed queen is in correct spot
        for (int i = 0; i < row; i++) {
            // check if the current column choose is in the same column with the previous queens
            if (columnForRow[row] == columnForRow[i] ||
                    // check diagonal
                    Math.abs(columnForRow[row] - columnForRow[i]) == row - i) {
                return false;
            }
        }
        return true;
    }