LeetCode 30 day Challenge | Day 15 | Product of Array except self (C++ & Java)

Sdílet
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

Komentáře • 9

  • @KnowledgeCenter
    @KnowledgeCenter  Před 4 lety +3

    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.

  • @adarshmv261
    @adarshmv261 Před 4 lety +2

    Appreciate your effort sir.... can you please include python code as well instead of Java or C++

    • @KnowledgeCenter
      @KnowledgeCenter  Před 4 lety +4

      Haha. Will definitely try from next video. I hope nobody asks me for 4th language.

    • @lilacu
      @lilacu Před 4 lety

      Lol

  • @electricalcoder3025
    @electricalcoder3025 Před 4 lety +1

    Great content dude....keep moving...

  • @jaggujaggu2922
    @jaggujaggu2922 Před 4 lety +1

    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

    • @KnowledgeCenter
      @KnowledgeCenter  Před 4 lety +1

      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.

    • @jaggujaggu2922
      @jaggujaggu2922 Před 4 lety

      @@KnowledgeCenter tq bro