Programming Question — N Queens , Leetcode 51

  1. In this question, we are asked to find ways in which n queens can be placed in a n*n board without attacking each other.
  2. we will take a helper function in which we will pass rows staring from 0 and for each column we will see the position is safe for the queen or not.
  3. if the position is safe, we will add the position(row and column) to our queen set, and recursively call helper function for next row, and recursively remove the position from queens.
  4. for safety of any row and column, we will check the row and column are present in the queen set or not, if present, we will return false.
  5. lastly , we will convert queens into board as the positions where queens exist , insert ‘Q’ there otherwise insert ‘.’
  6. we will return result.

--

--

--

!Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The tale of my first hackathon

Flutter app from scratch part 4— implementing logic and styling the user interface

What We Need to Know for Mobile Application Tests

Hyper-V vs VMware vSphere, Which Solution Is Right for You?

CS373 Summer 2018: Yoshinobu Nakada

7 most popular CSS frameworks you need to learn in 2020

AEEE Cut off Marks vs Branch Vs Campus Scholarship slabs total seats 🔥

AEEE Cut off Marks vs Branch

Meet Glenn, Software Division leader at Arkafort

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Raj shukla

Raj shukla

!Engineer

More from Medium

Binary Tree (DFS application)

Leap Before You Look, Write More Elegant Code

Competitive Programming Grader For All Programmers

LeetCode — Find Peak Element