Score After Flipping Matrix - Leetcode 861 - Python

  Рет қаралды 8,666

NeetCodeIO

NeetCodeIO

Күн бұрын

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/score-a...
0:00 - Read the problem
3:30 - Drawing Explanation 1
8:48 - Coding Explanation 1
12:34 - Drawing Explanation 2
20:05 - Coding Explanation 2
leetcode 861
#neetcode #leetcode #python

Пікірлер: 28
@Yaqk
@Yaqk 16 күн бұрын
I hate it when I get so close to the answer but miss some small step🤦‍♂ Thanks for making these videos again, it really helps to hear someone speak and go over the problem
@ronbuchanan5432
@ronbuchanan5432 14 күн бұрын
I gotta say your ability to explain your thought process here was really good !
@MP-ny3ep
@MP-ny3ep 16 күн бұрын
Thank you so much again. Great explanation as always.
@ay5960
@ay5960 16 күн бұрын
There is a nuance, for the leftmost column we could either flip rows to make it all 1s, or we could flip rows to make it all 0s and then flip the first column to make it all 1s. Now the question is whether the two lead to different answers? The answer is no but this kind of elucidates that why the fact that greedy approach is working is not trivial. How do you know you get the global optimum solution rather than a local optimum one? The answer is that there is only one type of nuance and that is exactly what I mentioned above. Another question, what if we remove the fact that rows represent binary numbers and just simply want to maximize the number of 1s? I have no idea how to do this one.
@jhumpadas147
@jhumpadas147 16 күн бұрын
Great explanation🙏
@connies_slice_of_life
@connies_slice_of_life 16 күн бұрын
thanks for the awesome explanation!
@krateskim4169
@krateskim4169 16 күн бұрын
Thank you for the solution
@SanjayB-vy4gx
@SanjayB-vy4gx 16 күн бұрын
Thanks man❤
@ahmmedabdullahsaquif559
@ahmmedabdullahsaquif559 16 күн бұрын
Thank you sir
@tayeblagha484
@tayeblagha484 10 күн бұрын
thank you
@chien-yuyeh9386
@chien-yuyeh9386 16 күн бұрын
Nice🎉🎉
@vinayaksuthar2472
@vinayaksuthar2472 15 күн бұрын
"Thank you, it was helpful."
@skshaheen6309
@skshaheen6309 15 күн бұрын
I clicked the logic at 5:56 then I paused the video and wrote code to implement the logic. And it was shocking that I perfectly wrote the correct code with 100% beats and readability. And it is recommended to all watchers that don't watch any solution video complete. You should stop watching when you click the logic and try to implement code yourself.
@existanz
@existanz 16 күн бұрын
We can use xor for line 9-10 like: cnt += 1^grid[r][0]^grid[r][c]
@swanv951
@swanv951 16 күн бұрын
🙏🙏 for method 2
@EranM
@EranM 16 күн бұрын
yo neet, use a 2^n lookup table and reverse it. That will make the index consistent instead of COL -1 - m or whatever
@mralix9566
@mralix9566 16 күн бұрын
The NEET Streak Saver 🔥
@rajsh3285
@rajsh3285 13 күн бұрын
why are we not considering the case where we flip the most significant bit column wise then the we don't have to check the most significant value while calculating the number of Zeros/ones for other columns
@priyanshagarwal8490
@priyanshagarwal8490 10 күн бұрын
2055. Plates Between Candles... Next Please..
@user-ce6zj1dt4s
@user-ce6zj1dt4s 15 күн бұрын
why flip rows first not column first?
@aashishbathe
@aashishbathe 16 күн бұрын
I didn't get the intuition at first, but as soon as you said first column check for 0, to flip row, I understood the problem. Anyways, here's my code - class Solution: def matrixScore(self, grid: List[List[int]]) -> int: ROWS, COLS = len(grid), len(grid[0]) res = (2 ** (COLS - 1)) * ROWS for r in range(ROWS): if grid[r][0] == 0: for c in range(COLS): if grid[r][c] == 0: grid[r][c] = 1 else: grid[r][c] = 0 for c in range(1, COLS): count1 = 0 for r in range(ROWS): if grid[r][c] == 1: count1 += 1 if count1 > (ROWS // 2): res += count1 * (2 ** (COLS - c - 1)) else: res += (ROWS - count1) * (2 ** (COLS - c - 1)) return res
@aashishbathe
@aashishbathe 16 күн бұрын
This is basically the same way I thought of it, but then damn your use of ternary conditions makes some lines of code so much shorter!
@sathishn6708
@sathishn6708 16 күн бұрын
you can use grid[r][c] ^ 1 one line to flip
@aashishbathe
@aashishbathe 16 күн бұрын
@@sathishn6708 yeah that also works!
@pastori2672
@pastori2672 15 күн бұрын
wow brain go brrr
@naveenkumarreddybadduri7775
@naveenkumarreddybadduri7775 16 күн бұрын
Neet you are natu natu 😂
@priyanshagarwal8490
@priyanshagarwal8490 10 күн бұрын
2055. Plates Between Candles... Next Please..
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 41 М.
Can You Draw The PERFECT Circle?
00:57
Stokes Twins
Рет қаралды 91 МЛН
Joven bailarín noquea a ladrón de un golpe #nmas #shorts
00:17
Miracle Doctor Saves Blind Girl ❤️
00:59
Alan Chikin Chow
Рет қаралды 27 МЛН
Find the Safest Path in a Grid - Leetcode 2812 - Python
26:40
NeetCodeIO
Рет қаралды 10 М.
Minimum Cost to Hire K Workers - Leetcode 857 - Python
19:01
NeetCodeIO
Рет қаралды 11 М.
but what is 'a lifetime?
12:20
leddoo
Рет қаралды 56 М.
Find the Maximum Sum of Node Values - Leetcode 3068 - Python
17:50
Student Attendance Record II - Leetcode 552 - Python
27:10
NeetCodeIO
Рет қаралды 7 М.
All 39 Python Keywords Explained
34:08
Indently
Рет қаралды 89 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 114 М.
Can You Draw The PERFECT Circle?
00:57
Stokes Twins
Рет қаралды 91 МЛН