Help me out in this


@aa1 are u there kindly seeit??

@aa1 it is giving runtime error

Means you can only examine the vector size and return immediately. You can’t do other things such as declaring variables. If you do have some other operations before the examinations of empty vector, you will get the above warning.

after you do

    int x=v.size();
            for(int i=0;i<x-1;i++)

in line 32 you get wrong answers .debug your code for
[1,2,2,3,2,6,7,2,1,4,8]
5
correct output:1

@aa1 it is passing 20 out of 60 test case

Approach:

  1. precalculate at each position, i, the min length of array with target sum from left and from right respectively.
    a. fromLeft[i]: from the leftmost to position, i, (i.e. [0 .. i]) , the min length of the array with target sum
    b. fromRight[i]: from the rightmost to position, i, (i.e. [i .. n-1]) , the min length of the array with target sum

  2. use DP to find the min sum of length at each pisition, i. (i.e. , dp[i] = fromLeft[i] + fromRight[i+1])
    a. consider the minimal sum of two arrays’ length at each index, i. (i.e. min sum of length at index i = min length in the range of [0 .. i] + min length in the range of [i+1 .. n-1])
    b. reverse the given array and apply the same subfunction to simply the code.

  3. complexity
    a. Time complexity : O(N)
    b. Space complexity: O(N)

@aa1 https://ide.codingblocks.com/s/387735
this is my updated code passing 57 test cases out of 60
[2,1,3,3,2,3,1]
6
Output
6
Expected
5
i think my answer is correct

no the answer is correct
see this