[Solved] Sum of comma separated string like 4,1,3 by O(n)


OK… We are not a homework solving community here and you’ve got enough comments on the style of your question. Further, your problem does not seem to be C++, but algorithmic. I Hope you learn from it for your next questions. But I find this interesting.
Here’s an idea:

a) iterate all elements and calculate the sum of all elements -> O(n)

b) iterate all elements and put out (sum – element) -> O(n)

O(n)+O(n) = O(n)

solved Sum of comma separated string like 4,1,3 by O(n)