Maximum Length of Repeated Subarray | leetcode 718 | Live coding session

Sdílet
Vložit
  • čas přidán 11. 09. 2024

Komentáře • 19

  • @algorithmo134
    @algorithmo134 Před 3 lety +5

    I thought my battery was low but it was from your video :)

  • @gmmkeshav
    @gmmkeshav Před 2 lety +2

    you are the best

  • @jessanraj9086
    @jessanraj9086 Před 2 lety +1

    Great explanation

  • @krateskim4169
    @krateskim4169 Před 2 lety +1

    awesome

  •  Před 3 lety +1

    Great and amazing short solution.

  • @theinvestorengineer
    @theinvestorengineer Před 3 lety

    great video! really need to wrap my head around on these DP tables

  • @jessanraj9086
    @jessanraj9086 Před 2 lety

    Hi sunchit bro ,I'm curious regarding what would the time complexity be if we don't use the 2d - dynamic programming approach

  • @praveenj3112
    @praveenj3112 Před 3 lety +1

    Thank you so much for great explanation.

  • @tathagatnegi5923
    @tathagatnegi5923 Před 3 lety +1

    Thanks

  • @paolavela8233
    @paolavela8233 Před 3 lety +1

    You briefly touched on returning the values of the subarray- Could you please explain that further ?

    • @CodeWithSunchitDudeja
      @CodeWithSunchitDudeja  Před 3 lety +1

      find the location of maximum entry in the matrix, and traverse in the upwards diagonal direction to build your result. Refer to the diagram you will understand.

  • @NS-te8jx
    @NS-te8jx Před 2 lety

    this solution exceeds time limit for the following case
    import numpy as np
    class Solution(object):
    def findLength(self, nums1, nums2):
    """
    :type nums1: List[int]
    :type nums2: List[int]
    :rtype: int
    """
    max_sub = 0

    # create a dynamix programming matrix of size mxn
    d = np.zeros((len(nums1)+1, len(nums2)+1), dtype=np.int32)

    for i, c1 in enumerate(nums1):
    i+=1
    for j, c2 in enumerate(nums2):
    j+=1
    # because we added an extra space to the front of both nums
    if c1==c2:
    d[i][j] = d[i-1][j-1]+1
    if d[i][j] > max_sub:
    max_sub = d[i][j]
    return max_sub
    input = [0,0,0,1,0,1,1,0,1,1,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0,1,1,0,0,0,0,1,1,1,1,1,0,0,1,0,1,1,1,0,1,1,1,0,1,0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0,1,1,1,0,0,1,0,1,1,1,0,1,0,0,1,1,0,0,0,1,0,1,1,0,0,0,1,0,1,1,0,1,1,1,0,0,0,0,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,0,0,0,1,0,0,1,1,1,0,1,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,1,1,1,1,0,0,0,0,0,1,0,1,0,0,1,0,0,0,0,1,1,1,0,0,1,1,0,1,0,1,1,1,1,1,1,0,0,1,1,0,0,1,0,1,1,1,0,1,1,0,0,1,1,1,0,0,0,0,0,1,0,1,1,1,1,0,1,1,0,0,0,0,0,0,0,1,1,0,0,1,1,0,1,1,1,1,1,0,0,1,0,0,0,0,1,1,0,0,0,1,0,1,1,0,1,1,0,0,0,0,0,1,0,0,0,1,1,0,1,1,0,0,1,1,1,0,0,0,1,1,0,1,0,1,0,0,1,1,1,0,1,1,0,1,1,0,1,0,0,1,1,0,0,1,0,0,0,0,1,1,1,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,0,0,0,1,1,0,0,0,1,1,1,1,0,1,1,0,0,0,1,0,1,0,0,0,1,1,0,1,1,1,1,1,0,1,0,1,0,1,1,0,0,1,0,1,0,1,1,0,1,0,0,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,1,0,0,0,1,0,0,1,1,0,0,0,0,1,1,1,1,0,0,1,1,1,1,1,0,1,0,0,0,1,0,0,1,0,0,1,1,1,1,1,0,1,0,1,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,1,1,1,1,0,0,0,0,0,0,1,1,0,0,1,1,0,1,1,1,0,1,0,0,1]
    output = TimeLimit exceeded

  • @SumitKumar-hd5vg
    @SumitKumar-hd5vg Před 3 lety +1

    Thanks sir

  • @syedhabeebuddin101
    @syedhabeebuddin101 Před 3 lety

    Thanks a lot dude !
    btw...what's your good name ?

  • @GurgaonKiEngineer
    @GurgaonKiEngineer Před 3 lety

    Bhaia , Why do we take the dp size length+1