Ad
  • 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.