Problem in Chefina and prefix suffix sum


consider
4
1 2 2 3
then prefix sum=>1 3 5 8
suffix sum=>3 5 7 8
possible pairs are {1,7} {3,5} {3,5}
1 3 3
series 1=>1 2 0 5
arranging(1 3 3)=> 3 3 1
series 2=>3 0 -2 7
arranging(1 3 3)=> 3 1 3
series 3=>3 -2 2 5

Next possible pair=>1 5 5
similarly i will do like above and get 3 possible arrangements

Next possible pair=>1 3 5
similarly i will do like above and get 6 possible arrangements

Next possible pair=>1 5 3
similarly i will do like above and get 6 possible arrangements

Next possible pair=>7 5 5
similarly i will do like above and get 3 possible arrangements

Next possible pair=>7 3 5
similarly i will do like above and get 6 possible arrangements

Next possible pair=>7 3 3
similarly i will do like above and get 3 possible arrangements

Next possible pair=>7 5 3
similarly i will do like above and get 6 possible arrangements

ANS=>36
IS THIS CORRECT??

It’s 0. You are given the prefix and suffix sums. You can’t take the prefix sum of the input.
Also 1 5 3 is arranged 6 times and so is 1 3 5. Which is overcounting. Same can be said for 7 3 5 and 7 5 3. So the answer is 24.

1 Like

THANKS !!!
consider
4
1 3 5 8 3 5 7 8
possible pairs are {1,7} {3,5} {3,5}
1 3 3
series 1=>1 2 0 5
arranging(1 3 3)=> 3 3 1
series 2=>3 0 -2 7
arranging(1 3 3)=> 3 1 3
series 3=>3 -2 2 5

Next possible pair=>1 5 5
similarly i will do like above and get 3 possible arrangements

Next possible pair=>1 3 5
similarly i will do like above and get 6 possible arrangements

Next possible pair=>7 5 5
similarly i will do like above and get 3 possible arrangements

Next possible pair=>7 3 5
similarly i will do like above and get 6 possible arrangements

Next possible pair=>7 3 3
similarly i will do like above and get 3 possible arrangements

ANS=>24
(3! / 2!)*2^3=24

1 Like

Also you can use$ (3!/2!) *2^3$ to make it look neater. It will look like this
(3!/2!) *2^3

1 Like