Definition of "Subarray"?


  • 5

    The questions states(on June/17):

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.

    Beware of the definition of "subarray", subarray don't have to be continuous.What is difference between subarray and contiguous subarray?

    I tried test case: [1,-2,3], 4.

    The top-voted solution and the OJ both return 0, rather than 2 ({1,3}).
    0_1496536668876_捕获.JPG

    Let's assume the question take non-continuous subarray into account, any idea on solving the non-continuous subarray case? It seems that O(N) time is hard.

    Thanks in advance.


  • 0
    I

    I'm agree with you. I was puzzled by the subarray definition for a while, cuz it's impossible to get max length in O(N) time.


Log in to reply
 

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