Please provide solutions/approach anyone?
Minimize multiplication can be solved by brute-force.
Consider pos be number of +1 in the resultant array and neg be the number of -1. So value of B = pos * (pos - 1 - neg) - neg * pos + neg * (neg - 1). Now run a loop changing pos = A ... 0 and neg = 0 ... A and find the minimum positive B.
A solution to 1st Problem.
Solution
vector<int> res;
int x = ceil((n + sqrt(n)) / 2);
for(int i = x; i < n; ++i) res.push_back(-1);
for(int i = 0; i < x; ++i) res.push_back(1);
return res;