Ad
  • Custom User Avatar

    Considering the return type is unsigned int, you should use an unsigned int for the running sum, as it (normally) has a greater range of values than int. And signed integer overflow is undefined behavior. Unsigned integer overflow isn't - you could safely overflow and underflow and still arrive at the correct answer as long as it fits in unsigned int.