N-Queens II - Leetcode 52 - Python

preview_player
Показать описание


0:00 - Read the problem
1:40 - Drawing Explanation
8:45 - Coding Explanation

leetcode 52

#coding #interview #python
Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.
Рекомендации по теме
Комментарии
Автор

Your observation of how to check the vacant positive/negative diagonal cells is brilliant

Hiroki-Takahashi
Автор

Just want to thank you for making these vidoes! You are awesome and helping a ton of people !!

stacysealkylee
Автор

Appreciate the consistent vids. Also, this is just what I needed for the daily challenge! :P

vasujain
Автор

That nonlocal keyword was exactly what I was looking for! I had thought it was global. I ended up just creating the count upon initialization.

Raymond-Wu
Автор

You make this problem super easy! Thanks!

李建宏-cy
Автор

Hi, I really like the way you describe the problem and solution. The conditions in the back track function should be or instead of and condition. Thanks a lot Man!!

kasivisu
Автор

What is the difference between the queen 1 sol? It is exactly this one, besides counting instead of returning a one sol.
So the time complexity is the same approximately

orellavie
Автор

We can ignore rows because of pigeonhole principle, each row must have a queen. If there are n - 1 rows and we have n queens then it is impossible to have a solution.

I think this is the best way to explain it

derpy
Автор

A lot of the times the board is identical if you rotate it by 180 degrees, which means you can cut the running time by almost half doing this optimization. This is easier to do when only number of possible orientations are asked, and I guess this is why this question is called n-queens 2.
Maybe you could make a video with the optimization later.

You can still do an optimization in the original n-queen but it is much much harder to do.

oneepicsaxguy
Автор

How does the code identify different solutions, so when we use backtrack, we can come up with one working solution, how can we continue from the start after finding one working result?

ishanmamadapur
Автор

Hey neetcode, do you think you could have a go at 1105 filling bookcase shelves? thanks

CS_nb
Автор

What would be a better way for Python(not python3) to deal with the non-local variable WITHOUT creating a list and returning the len(list)?

melissac
Автор

N-Queens: The problem - HARD level => NeetCode: its a easy problem
N-Queens II: supposed to be harder that the first one => NeetCode: its easier than the first N-Queens

youngtraveler
Автор

Hey, Great video. It was very helpful. Can I ask you what software do you use for the pen?

chrisgalanis
Автор

Hi there! absolutely love your explanations, could you please make an explanation video on 164 Maximum Gap which uses Radix/Bucket sort? Thank you

itsrdb
Автор

can someone please explain me that how would the res pointer increment each time as a solution is found as the pointer is written to be incremented only when r==n, so that must be only for once then right? please guide me through

mehvashkhan
Автор

i copy pasted n-queens and returned len(res) and well it worked, hahah :)

kanishkkala
Автор

what app are you use for drawing over?

thesouthsidedev
Автор

Hey hey! I think you reversed posDiag and negDiag set calculation. It doesn’t affect it as long as you keep it consistent (which you did). posDiag should be (r-c), such as 0-0, 1-1, 2-2, which all equal 0. negDiag should be (r+c), such as 3+0, 2+1, 1+2, which all equal 3.

benjaminkeene
Автор

Could you please do "sudoku solver" next?

abhishaiwinston