Leetcode - Transform to Chessboard (Python)

preview_player
Показать описание
September 2021 Leetcode Challenge
Leetcode - Transform to Chessboard #782
Difficulty: Hard
Рекомендации по теме
Комментарии
Автор

I ran into a counterexample of [[0, 0, 0], [0, 0, 1], [0, 0, 0]]. The code in the video outputs 2, but it should be -1. The chessboard cannot be made if either the two row patterns or the two column patterns are not complimentary to each other. To my knowledge, adding the following code between line 11 and line 12 can work:
r_pat1, r_pat2 = cnt_r[0][0], cnt_r[1][0]
c_pat1, c_pat2 = cnt_c[0][0], cnt_c[1][0]
if not all(r_pat1[i]^r_pat2[i] for i in range(n)):
return -1
if not all(c_pat1[i]^c_pat2[i] for i in range(n)):
return -1

DrDYC
Автор

Hello Timothy ... i have been following your channel and also solved many problems with the help of your videos..could you please do videos related to Object Oriented Design Problems too..most of the videos you can find in youtube are in java ...try to do some videos for classic questions like parking lot, ticket booking system and meeting rooms

errnil
Автор

It's impressive how you can solve all those problems so easily.

I did notice the mistake with the ">2" instead of ">1" right away while you typed it, but whenever I make such a mistake I would not be able to fix it without leaving the problem be for a while and revisit it at some later point. I'd never just find the thought error that actually is still active in my mind.
How do you do that?

Keep going and thank you for all the educational content!

svenvancrombrugge
welcome to shbcf.ru