CAn you please help me solving this
Leetcode array doubt
hello @Somasree
it seems easy.
observe one thing answer of particular subsequence depends only on it minimum and maximum element right.
so what we can do is we can fix minimum and maximum and then find how many subset will contain this.
so if we sort array and if we pick ith and jth index then for elements that falls in between i and j have two options either it will come in subsequence or not.
thats why -> (A[i]-A[j] ) * 2^(j-i-1)
take summation of all i,j valid pairs and print
please show me how the result 6 is coming in thw example given in the question
after sorting
[1,2,3]
[1,2] (min 1 and max 2 how many subset will hold this true only [1,2]) count=1 * (2-1)=1
[1,3] (min 1 and max 3 how many subset will hold this true total 2 ->[1,3],[1,2,3] )
count=2 * (3-1)=4
[2,3] (min 2 and max 3 how many subset will hold this true total 1->[2,3])
count=1* (3-2)=1
add all counts u will get 6
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.