Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
You can look up the 1 to n math formula. When you learn sums of series in school you often learn the 1 to n formula and you have to reorginize it with two variables to get from a to b.
I ran into this too. Looks like it says new array in the problem statement.
std::vector::size()
returns an unsigned integer type and thus unsigned integer arithmetic applies.If
numbers
is empty,numbers.size() - 1
will be evaluated to18446744073709551615
(orstd::numeric_limits<std::vector<int>::size_type>::max()
).std::vector::size()
returns an unsigned integer type, so beware of unsigned integer arithmetic.If
numbers
is empty,numbers.size() - 1
will be evaluated to18446744073709551615
(orstd::numeric_limits<std::vector<int>::size_type>::max()
).I think the best practice to check for empty vector has always been
empty()
and notsize()
, sinceempty()
guaranteesO(1)
complexity regardless of the container of the vector.shouldn't the condition i < numbers.size() - 1 be enough to check for the size being <= 1. The for loop shouldn't run at all in that case and the empty vector would get returned. I find the need for a redundant check case confusing. It would seem to me that this is a bug, or an idiosyncrosy of how codewars treats c++?
This comment is hidden because it contains spoiler information about the solution