private void helper(final int n, final int row, final int[] columnForRow, final List<String[]> res) {

        if (row == n) {
            // store one solution
            final String[] item = new String[n];
            for (int i = 0; i < n; i++) {
                final StringBuilder strRow = new StringBuilder();
                for (int j = 0; j < n; j++) {
                    // mark the correct column
                    if (columnForRow[i] == j) {
                        strRow.append('Q');
                    } else {
                        strRow.append('.');
                    }
                }
                item[i] = strRow.toString();
            }
            // add one solution
            res.add(item);
        }

        // big loop to get all possible ways
        for (int i = 0; i < n; i++) {
            // checking all possible columns for each given row
            columnForRow[row] = i;
            if (check(row, columnForRow)) {
                helper(n, row + 1, columnForRow, res);
            }
        }

    }