Ad
  • Custom User Avatar

    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.

  • Custom User Avatar

    I ran into this too. Looks like it says new array in the problem statement.

  • Custom User Avatar

    std::vector::size() returns an unsigned integer type and thus unsigned integer arithmetic applies.
    If numbers is empty, numbers.size() - 1 will be evaluated to 18446744073709551615 (or std::numeric_limits<std::vector<int>::size_type>::max()).

  • Custom User Avatar

    std::vector::size() returns an unsigned integer type, so beware of unsigned integer arithmetic.
    If numbers is empty, numbers.size() - 1 will be evaluated to 18446744073709551615 (or std::numeric_limits<std::vector<int>::size_type>::max()).

  • Custom User Avatar

    I think the best practice to check for empty vector has always been empty() and not size(), since empty() guarantees O(1) complexity regardless of the container of the vector.

  • Custom User Avatar

    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++?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution