N-Queens - Backtracking - Leetcode 51 - Python

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


0:00 - Read the problem
3:56 - Drawing Explanation
12:27 - Coding Explanation

leetcode 51

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

Backtracking never been this easy after watching your video! Thanks for the excellent intuition about backtracking.

Cld
Автор

I love so much the idea of using posDiag set and negDiag set. That is the truly brilliant trick.

wookyumkim
Автор

such an elegant and simple solution without having to pass through loads of different function unlike other videos I've seen. Thank you for this.

harishsn
Автор

Like the clear explanation of the problem and the code walkthrough. Please provide your analysis on the time/space complexity for each problem you are solving.

arjunv
Автор

I have been watching several videos on n-queen, your video is the most understandable

salehsaeed
Автор

I had seen this problem for the first time about 7 years ago in uni and I was too scared to even attempt it.

Thanks for explaining it so beautifully and helping me conquer my fear. (I was so stupid to be scared of this problem lol)

rajrsa
Автор

I was a bit confused by the problem statement, but your explanation made it looks as simple as possible. Thanks for making such amazing content.

chaitu
Автор

Altough it's an understandable reflex to use a 2d-array to represent this chess board, since a normal chess board is a matrix, in this case that's subobtimal. Since the problem definition is so that you can have only one queen/row anyways you can just get away with a regular array<int>. When you do this checking for conflicts also becomes less computationally expensive since you can just do this: Let b equal chessBoard, if b[row] == b[i] || abs(b[i] - b[j]) == abs(i - j)), conflict found. This probably doesn't matter for small n but once n gets moderately large every little bit starts to add up, especially if your method is time complexity O(n!) as in the video here.

slygg
Автор

I can't express how this explanation blew my mind! You're the best, thank you.

umutkavakli
Автор

Easily the best explanation on the internet thank you so much for your contributions :)

jadkhalil
Автор

Awesome, I solved it by using a helper to iterate through the rows then columns, then diags each separately O(N) for each of those loops, but this way is much better.
Thanks man

symbol
Автор

I started doing this problem and it was tricky, but the first part of the vid set me on the right track to code it up myself. Thanks bro

onlinealias
Автор

Brilliant solution; I learned a lot from the whole concept of (r+c) and (r-c); really great learning content.

LeeK
Автор

Whenever I watch you solve a problem I feel that if coding was Earth you are Mt Everest and I am Mariana Trench. One of the best and easily explained explanation

ramanpreetsingh
Автор

You explain difficult to understand concepts with amazing clarity, thank you for your work!

SameenIslam
Автор

For those who confused what's the purpose of backtrack(0) code, it's basically call the backtrack function starting at row 0

DanielTruongDev
Автор

This is the best video on backtracking I've seen so far. It was so good that I applauded after watching it.

vesicapiscis
Автор

In terms of the time complexity, don't forget cloning the memory of the board (n^2), except for it, I think the time complexity would be O(n*n!), cuz your tree has n layers, n! is just the number of the bottom level, so the total time complexity I think is O(n!*n + n!*n^2) = O(n!*n^2), that's why the bounce of n is pretty tiny (1 <= n <= 9)

Cakie-sogv
Автор

AWESOME! The best channel every for explaining problem-solving questions and how to think about them, rather than just throwing the solutions in front of the audiences. ❤

wessamyaacob
Автор

Thanks for speaking clearly...was able to watch this on 2x

parthsalat