Product of Array Except Self - Leetcode 238 - Python

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


0:00 - Read the problem
2:09 - Drawing Explanation
9:47 - Coding Explanation

leetcode 238

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

This problem is insane. After going through the explanation and the code initially I still didn't get it. I can't imagine coming up with this on the spot in an interview.

AndrewAffolter
Автор

For ones, who did not understand how prefix-postfix works, lets change 1, 2, 3, 4 positions to symbols like a, b, c, d, so multiplying will be:
prefix:
->
| a | a*b | a*b*c | a*b*c*d |
postfix:
<-
| a*b*c*d | b*c*d | c*d | d |

the result is a multiply without the symbol in own position (the left value from prefix and the right one from postfix):
| b*c*d | a*c*d | a*b*d | a*b*c |

rishatzak
Автор

Bro how do people manage to figure out these solutions?
You're some geniuses

symbol
Автор

there's literally no way anyone would ever come up with this algorithm on their own without seeing this exact problem before lol. these are the kinds of leetcode problems that are completely pointless to ask a candidate; you either see them solve some solution they memorized, or they give you n^2, neither really tell you anything about their ability

trevorbye
Автор

Quality is just unparalleled, the way you break down things is god-sent neet. First paycheck I get at a top company, I'll be sending things your way. Truly thank you neet!

Septix
Автор

Absolute legend, this problem almost shouldn't be medium, the logic of doing this without division is mind bending without your explanation

dylanmartin
Автор

I tried to understand the problem the way you taught and finally solve it on my own. I was able to produce the exact same code as you did, because the explanation was so detailed. I think moving forward, I need to spend a lot more time studying the logic before coding anything. I have an interview coming up and this insight will definately help me.

jaspindersingh
Автор

After solving 30 blind 75 problems I was able to draw and come up with a solution that is logically the same as preFix + postFix but with different names, and not as clean as yours. The key is to draw in paint or figma, and representing problems graphically, a thing I've learned watching your vids. Ty so much!

llRetro
Автор

Interviewer: BTW you can't use the division operator.

Me : Uses pow(num, -1).

Interviewer:😲

sharmanihal
Автор

You have to be super genius to have the intuition to come up with these kind of solutions first time in an interview. Unless there is a reliable systematic way to determine the problem space of the optimal solution you got to memorise the pattern. wtf.

mapo
Автор

transitioning to tech is the hardest thing I have ever done. I'd say leetcode is pattern recognition. I want to get better at visualing the code even before coding. This is something Neetcode has been teaching me. Thank you!

Prince-olzk
Автор

One important thing that lacks in this explanation, is the familiarity with the concept of "Prefix/Postfix Sum". I watched this solution without knowing that hence I was stuck but after knowing it I understood this.

AB-sdgx
Автор

I admire your ability to explain the solutions so well! Finding the solution at all is half the battle, the other half is being able to explain it well to the interviewers, especially when English is not your first language.

roman_mf
Автор

How can I like a video multiple times? This is extremely well-explained, man! Thank you for creating this video. You are an inspiration!

demiladeoyedele
Автор

I found the code to be more informative and easier to understand compared to the diagrams. The code provides a clearer and more precise explanation of the problem imo!

shreyaschaudhary-rd
Автор

I had my Amazon interview yesterday and was asked this question, I did the brute force solution and cleared the interview, but this solution is genius!

Joy
Автор

Not using the extra memory really impacts the code's readability. Unless there is serious performance requirement, write readable code not clever code.

shoooozzzz
Автор

Don't think I want a job anymore 🤣

deeprony
Автор

I had difficulty understanding the explanation. But it turns out that I didn't know how the postfix and prefix traversals worked. Understanding them helped me understand your explanation better.

nirvikdas
Автор

The reason you can’t do it with a divide is the second test case in the problem and a minor issue called a DIV0 error

snoopyjc