The maximum value of $k$ is 32. Let the number of students be $n$, then $980 \leqslant n \leqslant 989$.
On one hand, divide the students into 32 groups, with the first 31 groups each having 31 people, and the 32nd group having $m(19 \leqslant m \leqslant 28)$ people. Each group enters and exits the campus simultaneously, and there is no overlap in time between the groups. At any time, there are at most 31 students visiting the campus, and at most 32 students can be selected (one from each group) to ensure that none of them are in the campus at the same time. Thus, $k_{\max }=32$.
On the other hand, assume the maximum value of $k$ is $s \leqslant 31$, consider the first student to leave the campus $T_{1}$, and those who enter the campus before $T_{1}$ leave are called Group 1; after Group 1 clears out, the rest enter the campus again, and the first student to leave the campus is $T_{2}$, and those who enter the campus before $T_{2}$ leave are called Group 2; repeat this grouping method, and there will be a corresponding $T_{3}$ and Group 3, ..., $T_{t}$ and Group $t$, until all $n$ students are grouped.
In the above grouping, at any time, there is at most one group of students visiting the campus (by assumption, the number of people in this group does not exceed $s \leqslant 31$), and among $T_{1}, T_{2}, \cdots, T_{t}$, no two are in the campus at the same time, so $t \leqslant s \leqslant 31$. Therefore, the total number of people does not exceed $31 t \leqslant 31^{2}=$ $961<n$, which is a contradiction.
In conclusion, the maximum value of $k$ is 32.
3. A school is hosting a Mathematics Culture Festival. According to statistics, there were more than 980 (no less than 980, less than 990) students visiting the school that day. Each student visits for a period of time and then leaves (and does not return). If, regardless of how these students arrange their visit times, we can always find $k$ students such that either all $k$ students are in the school at the same time, or at no time are any two of them in the school at the same time. What is the maximum value of $k$?