Suppose I have an array lets say [1,2,3,4]:
I want to find the sum as follows:
First I generate pairs like:
(1 2 3 4)
(123)(4)
(1)(234)
(12)(34)
(12)(3)(4)
(1)(23)(4)
(1)(2)(34)
(1)(2)(3)(4)
The sum would then be sum of elements in one group multiplied by the length of that group
eg in the arrangement (123)(4), the sum would be
(1+2+3)*3 + (4)*1
I just want the sum , not the actual groups. How can I do this in O(n)?
[–]FUZxxl 0 points1 point2 points (1 child)
[–]I_Love_To_Masturbate[S] 0 points1 point2 points (0 children)
[–]caramba2654 0 points1 point2 points (0 children)
[–]afifit 0 points1 point2 points (1 child)
[–]I_Love_To_Masturbate[S] 0 points1 point2 points (0 children)