Pls explain me this question i can not understand the sample test case provided

3
1 -2 3

for given sample test case

  1. first you have to find maximum subarray sum for each subarray
  2. then remove duplicate number you can use case HashSet in java,and set like in other language
    3.and sum all unique value
    example
    subarrays
    1 =1
    1 -2=1
    1 -2 3=3
    -2 =-2
    -2 3=3
    3 =3
    remove duplicate
    and add value
    1 3 -2=2
    ans=2

but bro according to the question sample test case
one subarray is
5 -2 7 -3 but its sum is 10
and also of 5 -2 7 is 10
i didnt understand this only pls explain me this

because
its a continues subarray sum
so 5 + (-2)+7=10
10 is maximum continues subarray sum
example
5+(-2)=3
then 3+7=10
is maximum than 5+(-2) and (-2)+7
and we are taking 5 + 7 as sum because they are not continues

1 Like