Sample Approach

Problem – Print all unique combinations of setting N pieces on an NxN board

Approach: This problem can be solved by using recursion to generate all possible solutions. Now, follow the steps below to solve this problem:

  1. Create a function named allCombinations, which will generate all possible solutions.
  2. It will take an integer piecesPlaced denoting the number of total pieces placed, integer N denoting the number of pieces needed to be placed, two integers row and col denoting the row and column where the current piece is going to be placed and a string ans for storing the matrix where pieces are placed, as arguments.
  3. Now, the initial call to allCombinations will pass 0 as piecesPlaced, N, 0 and 0 as row and col and an empty string as ans.
  4. In each call, check for the base case, that is:
    • If row becomes N and all pieces are placed, i.e. piecesPlaced=N. Then print the ans and return. Else if piecesPlaced is not N, then just return from this call.
  5. Now make two calls:
    • One to add a ‘*’ at the current position, and one to leave that position and add ‘-‘.
  6. After this, the recursive calls will print all the possible solutions.

How to Write DSA Articles on w3wiki?

w3wiki provides all the coding enthusiasts an opportunity to showcase their programming and Data Structures & Algorithms skills by writing coding or DSA-based articles. However, a lot of individuals (especially college students or beginners) find it difficult to articulate their learnings & skills and contribute at w3wiki. But now the problem has got solved as this article will guide you through the entire process and guidelines of writing Programming/DSA articles at w3wiki.

Let’s get started:

First and foremost, you need to know how to get started with article writing at GFG along with various other fundamental aspects like why should you contribute, where to write, etc. You can check out this link to know all these details in a comprehensive manner.

Similar Reads

How to verify if we can write an article?

Now, you need to check whether you can write an article on a particular topic/problem or not. You can do the same by following the below-mentioned steps:...

Coding Article Format and Guidelines

Moving further, let’s check out the format and guidelines that you need to follow while writing a coding article at GeeksforGeeks. The programming articles should contain the following points:...

Approach Format

If the approach is:...

Sample Approach:

Problem – Print all unique combinations of setting N pieces on an NxN board...

How to Add Code in the Article?

Moving further, now you need to understand the process of adding the code in the article. It is as follows:...

Coding Standards

You need to ensure that you’re following the below-mentioned coding standards:...

Image Creation Guidelines

...