Whether the subarray should be continuous elements in the array?

  • 0

    the example gives the answer [4, 3] for array [2,3,1,2,4,3] when s = 7.

    can I give the answer of [3, 4], 3 is at index 1. Is that ok?

  • 0

    I think it should be continuous.

    I tried an algorithm which sorts the array and finds the maximum numbers the sum of which is >= s. If the subarray is allowed to be noncontinuous, these numbers consist a valid solution, but OJ did not accepted it. I guess, this is because that the (indices of the) numbers are not continuous.

  • 0

    I don't think you can do that. If you want to include the first 3, which index is 1, then the subarray length=4.
    for subarray, it should be continuous.

  • 0

    I got an error like this:
    Input: 11, [1,2,3,4,5]
    Output: 5
    Expected: 3
    So it is not necessarily continuous..........

Log in to reply

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