We have a sequence $a_1,a_2,...,a_n$ and $\forall i\in N;~~~ a_i\in\{1,2,3,...,n\}$. A sequence is $GOOD$ if we have that: For Every $k \in N$, we have $a_k≥a_i$ for every $i<k$, or $a_k≤a_i$ for every $i<k$. it means that every element is larger than all previous elements or smaller than all previous elements.
We want to find how many permutations of $1,2,3,...n$ are $GOOD$ ?
It was a question in an old exam and the answer was $2^{n-1}$ it said that in every choice, we can put the biggest or the smallest element from the remaining numbers, except that for the last one we have one choice so the answer is $2^{n-1}$. I don't completely understand this answer. (eg. if we follow this algorithm it could easily get to the point where we can't choose any other number: $1\to 1, \ n \to ?$ Can anyone explain this answer or give another answer for this question? Is this answer correct?
PS. Changed the condition so it is better understandable.
Note that the first two elements in the sequence must be adjacent to each other, but their order is irrelevant. So given a GOOD sequence $a_1,\ldots,a_n$ of length $n$, we can generate two GOOD sequences of length $n+1$:
$$a_1,a_1+1,b_2,\ldots,b_n$$ and $$a_1+1,a_1,b_2,\ldots,b_n$$
where $b_i=a_i$ if $a_i<a_1$, and $b_i=a_i+1$ if $a_i>a_1$. For instance, the sequence $23145$ generates $234156$ and $324156$. So we see that there are twice as many GOOD sequences of length $n+1$.