Suppose that I have a deck of $n$ cards numbered $1$ to $n$. I randomly draw the cards from the deck one by one and put them in piles according to the following rule:
The first drawn card forms the first pile.
For each subsequent card drawn, if the number on it is just smaller than the smallest number on cards in an existing pile by one, or just larger than the largest number on cards in an existing pile by one, then I will put this card on that pile.
If a newly drawn card cannot be put in any existing piles according to rule 2, then start a new pile with this card.
For example, if $n=6$ and the order of the cards drawn is $(2,5,1,3,6,4)$, then the piles of cards will be (step by step)
$(2)$
$(2), (5)$
$(12), (5)$
$(123), (5)$
$(123), (56)$
$(123), (456)$ or $(1234), (56)$
and I will have 2 piles.
My question is how to find the expected number of piles, $k$, I will get. My guess is $E[k] = (n+1)/3$.
We can calculate the expected number of new piles formed, starting with the available run $1\ldots n$, with three slightly different initial conditions:
Clearly $A_1=A_2=1$ and $B_1=C_1=C_2=0$ and $B_2=1/2$. Beyond this, we can calculate each sequence recursively by considering how the first card can be drawn and what available runs are formed thereby. Newly formed available runs will evolve independently. With no initial piles, the result is a newly created pile and either a shortened run with one neighboring pile (if the drawn card is $1$ or $n$) or two runs with one neighboring pile:
$$ A_n=1 + \frac{2}{n}B_{n-1}+\sum_{k=1}^{n-2}\frac{1}{n}\left(B_{k}+B_{n-1-k}\right)=1+\frac{2}{n}\sum_{k=1}^{n-1}B_k. $$ With an initial pile at $0$, the result is either a shortened run with one neighboring pile (if the drawn card is $1$), or a new pile and a shortened run with two neighboring piles (if the drawn card is $n$), or a new pile and a run with two neighboring piles and a run with one neighboring pile: $$ B_n=\frac{1}{n}B_{n-1}+\sum_{k=1}^{n-2}\frac{1}{n}\left(1+C_{k}+B_{n-1}\right)+\frac{1}{n}\left(1+C_{n-1}\right)=1-\frac{1}{n}+\frac{1}{n}\sum_{k=1}^{n-1}B_k+\frac{1}{n}\sum_{k=1}^{n-1}C_k. $$ Finally, with initial piles at $0$ and $n+1$, the result is either a shortened run with two neighboring piles (if the drawn card is $1$ or $n$), or a new pile and two runs with two neighboring piles: $$ C_n=\frac{2}{n}C_{n-1}+\sum_{k=1}^{n-2}\frac{1}{n}\left(1+C_{k}+C_{n-1-k}\right)=1-\frac{2}{n}+\frac{2}{n}\sum_{k=1}^{n-1}C_k. $$ We know that $C_2=0$; let's assume, as an inductive hypothesis, that $C_k=a(k-2)$ for $2 \le k < n$ (for some fixed $n > 2$, and with the value of $a$ to be chosen later). Then $$ C_n=1-\frac{2}{n}+\frac{2}{n}\sum_{k=3}^{n-1}a(k-2)=1-\frac{2}{n}+\frac{2}{n}\left(\frac{1}{2}a(n-2)(n-3)\right)=\frac{(a(n-3)+1)(n-2)}{n}. $$ The choice $a=1/3$ gives the self-consistent result $C_n=\frac{1}{3}(n-2)$. We conclude by induction that $C_n=\frac{1}{3}(n-2)$ for all $n\ge 2$. In an exactly analogous way, we can prove by induction that $B_n=\frac{1}{2}+\frac{1}{3}(n-2)$ and (OP's result) that $$A_n=1+\frac{1}{3}(n-2)=\frac{1}{3}(n+1) \qquad {\text{for }} n\ge 2.$$