Image Smoother - Leetcode 661 - Python

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


0:00 - Read the problem
0:30 - Drawing Explanation
4:35 - Coding Explanation
8:26 - Drawing Explanation Optimal
12:26 - Coding Explanation Optimal

leetcode 661

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

I solved this problem easily on my own the first way, but I was curious what kind of explanation you had with a 16 min video since I didn't think this problem warranted that amount of time. Glad I clicked cause that second solution is amazing. Even when I can solve these on my own, I get value from these videos. Thanks.

AMakYu
Автор

To get the last 8 bits (at line 14), you can also AND the number with 255. (AND operation is more efficient than mod).

chugisan
Автор

amazing. never thought that 255 constraint can be used to such solution

PegasusKr
Автор

If someone still has any confusion why we are using %256, Lets forget binary, think about a decimal number 23456. What if we want to get the last digit? we use %10. What if 2 digit? We just use %100 (10*10=10^2), incase of 3 digits %1000 (10*10*10= 10^3) and so on. We get a pattern here. It's like %base^num_of_digits.
In this problem we want to get the number that is represented by the last 8 bit. Now, just think in the decimal number way, if we want to get the last 8 digit what should we do? mod by 10^8 (following the pattern).
Incase of binary, base =2 and number of digits we want =8. So according to the pattern we have to do %2^8 which is equal to %256. So that's it what we are doing. (Hope it's not making the thing more complicated.)

It can be also done by &255 .

theruler
Автор

the optimal solution was pretty cool! Bit manipulation questions are so satisfying to solve!

hyperboliq
Автор

i'm amaze how you can come up with the optimal solution.

robin_c
Автор

What a lucid explanation! Keep this up!

syeedtalha
Автор

Great explanation as always. Thank you for the daily problems.

MP-nyep
Автор

this was a good solution, I solved it using the first approach and liked your second approach :)

a_maxed_out_handle_of__chars
Автор

Second solution was sooo intuitive man...

EzWorkzzStudios
Автор

Amazing naive explanation, helped understanding the rest of the video!

EzWorkzzStudios
Автор

Definitely medium problem and there is no way I would come up with the second solution.

shreehari
Автор

Why the memory is same before and after optimization on leetcode? I know in theory it should be less but I wonder why it works differently

jayberry
Автор

We learnt it in Digital signal processing. Couldn't understand the programming side of it. Thanks

GCKteamKrispy
Автор

Do we need to come up with the inplace solution in an interview?

il
Автор

For the second approach, instead of mod 256 would using logical & work? To remove everything besides last 8?

jamesabasifreke
Автор

I just wondering if you could use sums to avoid internal iteration for each element to make the algorithm a bit faster (roughly 9 times faster)

krzysztofsobocinski
Автор

I don't get why we need to XOR and can't just add?

CS_nb
Автор

thats not really constant space bro, cmon

adityaln