The last argument in accumulate (i.e. 0 in this case) should have same data type as that of array. So the following code fails (gives compilation error)
vector<long long int> v = {1, 3};
cout << accumulate(v.begin(), v.end(), 0) << '\n';
while the following passes
vector<long long int> v = {1, 3};
cout << accumulate(v.begin(), v.end(), 0LL) << '\n';
In template, we are accepting the type of elements that vector contains, but using accumulate as if vector contains only integers.
https://github.com/sahilbansal17/Competitive_Coding/blob/1403a763003397ef2f41baac8a7d19f958f16f76/cpp/array_helper.cpp#L20
The last argument in
accumulate
(i.e. 0 in this case) should have same data type as that of array. So the following code fails (gives compilation error)while the following passes
In template, we are accepting the type of elements that vector contains, but using accumulate as if vector contains only integers.