How to solve N Queen Problem?

A Quick Overview

A classic problem in CS where goal is to place N queens on a NxN chess board such that they do not attack each other by being in same row, column or diagonal.

What is N Queen Problem?

Given N = 8, one of the possible solution such that no queen attack any of other queens.

Example of N Queen Problem

We can place each queen in a different row, & then check if the square we are placing it in is safe due to previously placed queens. If there are no safe squares left, we can backtrack & return false.

Method 1 (Using Backtracking)

To solve the N-Queen problem, we use backtracking to reach the solution; however, we can add some optimizations to the solution.  But how?

How to implement these approaches in different programming languages?