Think about what possible inputs your parameters can represent, like the empty set and sets smaller than expected.
for (int i = 0; i < vect.size() - 2; i++) {
vect.size()
returns an unsigned size type. If vect
is smaller than the value you are subtracting, then your comparison will be i < huge number
, leading to access violations.
if (isSequence(vect[i], vect[i + 1], vect[i + 2])) {
If you startStart at i = 2
and compare to size without the subtraction, it'll just fail fast. That means your The conditional here should do the subtraction, which won't invoke the modulus behavior as your checked values are guaranteed to exist.
if (isSequence(vect[i-2], vect[i-1], vect[i])) {
// Checks: | | |
// [0,size-2) <┘ | |
// [1,size-1) <┘ |
// [2,size) <┘
Think about what possible inputs your parameters can represent, like the empty set and sets smaller than expected.
for (int i = 0; i < vect.size() - 2; i++) {
vect.size()
returns an unsigned size type. If vect
is smaller than the value you are subtracting, then your comparison will be i < huge number
, leading to access violations.
if (isSequence(vect[i], vect[i + 1], vect[i + 2])) {
If you start at i = 2
and compare to size without the subtraction, it'll just fail fast. That means your conditional here should do the subtraction, which won't invoke the modulus behavior.
Think about what possible inputs your parameters can represent, like the empty set and sets smaller than expected.
for (int i = 0; i < vect.size() - 2; i++) {
vect.size()
returns an unsigned size type. If vect
is smaller than the value you are subtracting, then your comparison will be i < huge number
, leading to access violations.
if (isSequence(vect[i], vect[i + 1], vect[i + 2])) {
Start at i = 2
and compare to size without the subtraction. The conditional here should do the subtraction, which won't invoke the modulus behavior as your checked values are guaranteed to exist.
if (isSequence(vect[i-2], vect[i-1], vect[i])) {
// Checks: | | |
// [0,size-2) <┘ | |
// [1,size-1) <┘ |
// [2,size) <┘
Think about what possible inputs your parameters can represent, like the empty set and sets smaller than expected.
for (int i = 0; i < vect.size() - 2; i++) {
vect.size()
returns an unsigned size type. If vect
is smaller than the value you are subtracting, then your comparison will be i < huge number
, leading to access violations.
if (isSequence(vect[i], vect[i + 1], vect[i + 2])) {
If you start at i = 2
and compare to size without the subtraction, it'll just fail fast. That means your conditional here should do the subtraction, which won't invoke the modulus behavior.