array extension function

void ext(int n) {
  int newSeq[seqLength+1];
  free(sequence);
  sequence = newSeq;

a, b, and newSeq are "local variables" in C and C++, not dynamically allocated objects. That means that they essentially disappear when the function where they were defined (setup() or ext()) returns; local variables are typically allocated on the stack, and that part of the stack is likely to be reused the next time you call a function.

This means that your pointer variable "sequence" is left pointing to memory that no longer contains the variables or values that you think it does.

Also, you cannot free() local variables, since they were not allocated from the dynamic memory pool.

You could probably do what you're trying to do by using malloc() to allocate the new sequence storage, but that's really unnecessarily complex and inefficient on a small microcontroller. You might as well implement your array as a global variable/array with the maximum size you want to allow, and keep track of how many values are in it at the moment. (This is essentially doing your own memory allocation, but in a very simplified form that is less prone to errors and easier to debug.)