Though I could understand what the solutions were doing there was not much for the intuition behind it. This puts that crucial piece of the puzzle together. Thank you
My only question is how do you even start coming up with an algorithm to solve it, i understand the solution but coming up with the solution in the first place is difficult for me, how do you think to start doing left and right products and multiply them?
I would give two suggestions for this. First, come up with an "dumb" brute force solution, then try to identify where improvements could be made. For this problem, I noticed that we were doing the same calculations over and over again, which was a hint that the optimal solution should only calculate each product once. Second, if you're really stuck and can't figure out the answer, it's ok to look at the solution, but take some time to really understand why the solution works. If you can understand how and why it works, it'll become easier for you to spot similar patterns in other problems.
Your explanation is really good but when u fill up the left and right, ur red line of box is not easy to understand. Instead of that, just say multiply every left side or multiply every right side elements. Not like one by one. For example, when we calculate every left side of 5, say 2*3*4. And I think until 4:12 mins are enough to understand this question. Thank you for your explanation.
I really appreciate the explanation and how you visualize the problem! Great stuff!
Very clear concise explanation and visualisation! Thank you very much and please keep posting! You are highly appreciated!
Once again, best visuals and explanation out there!
the grid visualization really helped. finally understood this problem thank you
Once again, best explanation and visuals out there, thank you!
perfect . simplified .really easy to understand .kudos man . cant wait for more
Awesome! Been waiting for this one!
Very clear explanation, thanks!!!
Though I could understand what the solutions were doing there was not much for the intuition behind it. This puts that crucial piece of the puzzle together. Thank you
by far the easiest explaination
Thank you!
Great explanation, i ha to watch it 2 times, but i understood it
thanks for this, and thanks for the captions.
Great explanation!
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
i = 0
length = len(nums)
j = length - 1
left = list([1]);right = list([1])
for i in range(length-1):
left.append( left[i] * nums[i] )
right.append( right[i] * nums[j] )
# backwards
j -= 1
right.reverse()
out = [ i * j for i, j in zip(left, right) ]
return out
My only question is how do you even start coming up with an algorithm to solve it, i understand the solution but coming up with the solution in the first place is difficult for me, how do you think to start doing left and right products and multiply them?
I would give two suggestions for this. First, come up with an "dumb" brute force solution, then try to identify where improvements could be made. For this problem, I noticed that we were doing the same calculations over and over again, which was a hint that the optimal solution should only calculate each product once. Second, if you're really stuck and can't figure out the answer, it's ok to look at the solution, but take some time to really understand why the solution works. If you can understand how and why it works, it'll become easier for you to spot similar patterns in other problems.
@@AlgoEngine I see, thank you! i guess it comes down to practice, kind of sad i dont have a natural talent for spotting solutions :(
@@azka9075 It definitely comes down to practice! I promise it gets easier the more you practice 🙂
Your explanation is really good but when u fill up the left and right, ur red line of box is not easy to understand. Instead of that, just say multiply every left side or multiply every right side elements. Not like one by one.
For example, when we calculate every left side of 5, say 2*3*4.
And I think until 4:12 mins are enough to understand this question.
Thank you for your explanation.
thank you so much, good work...
This is amazing, thanks man
thank you very much
Could you also find the product of all elements, and divide by each num[i] to create the product array
Unfortunately, the question prohibits us from using division (0:21) but if division was allowed, then yes, that would probably be the best way!
@@AlgoEngine nums = [3, 2, 4,0]
res=[]
nums1=copy.copy(nums)
print(nums1)
for i in range(0, len(nums1)):
nums1.remove(nums[i])
prod=reduce((lambda x,y:x*y),nums1)
res.append(prod)
nums1.insert(i,nums[i])
return(res)
My Solution
nums = [3, 2, 4,0]
res=[]
nums1=copy.copy(nums)
print(nums1)
for i in range(0, len(nums1)):
nums1.remove(nums[i])
prod=reduce((lambda x,y:x*y),nums1)
res.append(prod)
nums1.insert(i,nums[i])
return(res)
Could you use C++, Java or C#, please? Python is hard to read.
discord server?
No discord server right now, but I may make one in the future!