Getting memory limit exceeded?


  • 0
    R

    Hello,

    I'm using a 2d array to store all the results of sums beginning from the indexes [0..5], [1..5], [2..5] and so on. How do I improve? There has to be some storage to retrieve the results fast right?


  • 0
    G

    think about that:
    if u kown [0..4] how do u get [0..5]?
    u just [0..4] + [5]
    [0..4] = [0..3] + [4]
    [0..3] = [0..2] + [3]
    .....
    u can do it in o(n)

    and
    [5..2] = [0..5] - [0..2] + nums[2]

    do u get it?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.