We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

can U explain me about 2 lines of your code?:
for(auto it = s.cbegin(); it != s.cend(); ++it){
if(d == std::accumulate(it, it + m, 0))
I think a accumulate will sum element out of vector, I think it will be it != cend() - m more saver.

## Birthday Chocolate

You are viewing a single comment's thread. Return to all comments →

Same approach, but with iterators instead.

I believe this is O(n^2). O(n) is also possible.

The OP is O(n)

It's O(nm).

its o(n^2), coz in worst case senario, all the choclate blocks would add up to d.

I have implemented it in O(n).

can you show your logic ???

Why call accumulate function every iteration when you add only one square ? It's not the same approach : you are O(nlog(n)), his solution is in O(n)

can U explain me about 2 lines of your code?:

`for(auto it = s.cbegin(); it != s.cend(); ++it){ if(d == std::accumulate(it, it + m, 0))`

I think a`accumulate`

will sum element out of vector, I think it will be`it != cend() - m`

more saver.