zargus
1
Pls suggest an algorithm to find the maximum no. of subset of length k in an array of length m where k<=m , having sum equal to a constant factor…
e.g
an array of length 11
2 5 1 2 4 1 6 5 2 2 1
k=6,
constant factor = sum of largest k values in the array= 6 + 5 + 5 + 4 + 2 + 2 = 24 ??
copy the values into a new array name sbs length k.
then find max either with what ever build in function or write it down your self.
hint for max func()
for i =0 i<k-1 i++
{
if sbs[i]<sbs[i+1]
max= sbs[i+1]
else if sbs[i]>sbs[i+1]
max =sbs[i]
else if sbs[i] = sbs[i+1]
Continue
}
sbs: short of subset
zargus
3
i need to find the max no. of subset of length k not max k !!
@zarqus I edited above answer to make sense, look at it now.
Advice: extract the code on sperate lines, it will be more clear.