LeetCode 30 day Challenge | Day 15 | Product of Array except self (C++ & Java)
Vložit
- čas přidán 6. 09. 2024
- Complete Playlist LeetCode Solutions: • LeetCode Solutions | L...
*** Best Books For Data Structures & Algorithms for Interviews:*********
1. Cracking the Coding Interview: amzn.to/2WeO3eO
2. Cracking the Coding Interview Paperback: amzn.to/3aSSe3Q
3. Coding Interview Questions - Narasimha Karumanchi: amzn.to/3cYqjkV
4. Data Structures and Algorithms Made Easy - N. Karumanchi: amzn.to/2U8FrDt
5. Data Structures & Algorithms made Easy in Java - N. Karumanchi: amzn.to/2U0qZgY
6. Introduction to Algorithms - CLR - Cormen, Leiserson, Rivest: amzn.to/2Wdp8rZ
*****************************************************************************
LeetCode 30 day Challenge | Problem 15 | Product of Array except Self | 15 April
Facebook Coding Interview question,
google coding interview question,
leetcode,
Product of Array,
Product of Array except self,
#Amazon #Facebook #CodingInterview #LeetCode #30DayChallenge #Google #StringShifts
Please share your solutions - no matter whether it's O(1) space or O(n) space in the comments. I have added C++ and Java codes for both the approaches in the video.
Appreciate your effort sir.... can you please include python code as well instead of Java or C++
Haha. Will definitely try from next video. I hope nobody asks me for 4th language.
Lol
Great content dude....keep moving...
Thanks, will do!
import itertools
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
l=[]
k=list(itertools.combinations(nums,len(nums)-1))
def multiplyList(myList) :
result = 1
for x in myList:
result = result * x
return(result)
for i in k:
l.append(multiplyList(i))
l=l[::-1]
return(l)
i am a begginer, bro can u help me with this code i am not able to pass all testcases
Your solution doesn't look O(n) time. In your code k is a list of all subsequences of n-1 length. Then you are iterating each list and multiplying.
So, multiplying all elements of 1 list is O(n). So, do this for n lists. So, overall time complexity is O(nxn) = O(n2).
All test cases will pass if you implement O(n) solution.
Try avoiding many repeated multiplications, with the approach explained in video.
@@KnowledgeCenter tq bro