A castle has a number of halls and $n$ doors. Every door leads into another hall or outside. Every hall has at least two doors. A knight enters the castle. In any hall, he can choose any door for exit except the one he
just used to enter that hall. Find a strategy allowing the knight to get outside after visiting no more than $2n$ halls (a hall is counted each time it is entered).
1. **Graph Representation**:
   - Consider the graph \( G \) where the halls are vertices and the doors are edges.
   - Add an additional vertex \(\Omega\) representing the "outside".
   - The degree of \(\Omega\) is at least 1 (\(\deg(\Omega) \geq 1\)) since the knight can exit the castle.
   - Each hall \( h \) has at least two doors (\(\deg(h) \geq 2\)).

2. **Path Construction**:
   - Let \( h_1 \) be the hall where the knight starts.
   - Construct a path \( P \) starting at \( h_1 \) with no repeating vertices (halls) and thus no repeating edges (doors).

3. **Case 1: Path Reaches Outside**:
   - If the path \( P \) reaches \(\Omega\), the knight exits the castle.
   - The maximum number of halls visited in this case is \( n-1 \) (since there are \( n \) doors and each hall has at least 2 doors).

4. **Case 2: Path Ends in a Hall**:
   - If the path \( P \) does not reach \(\Omega\), it will end at some hall \( h_m \).
   - At this point, any new door from \( h_m \) will lead to a previously visited hall \( h_k \) for some \( 1 \leq k \leq m-2 \).

5. **Constructing the Walk \( W \)**:
   - The knight can follow the walk \( W = h_1 h_2 \ldots h_m h_k h_{k-1} \ldots h_2 h_1 \Omega \).
   - This walk involves \( k + (m-k+1) = m+1 \) different doors.
   - Since \( m \leq n-1 \), the number of different doors is at most \( n \).

6. **Counting the Halls Visited**:
   - The number of halls visited in the walk \( W \) is \( 2k + (m-k) = m+k \).
   - Since \( k \leq m-2 \), we have \( m+k \leq 2m-2 \).
   - Given \( m \leq n-1 \), it follows that \( 2m-2 \leq 2(n-1)-2 = 2n-4 \).

7. **Conclusion**:
   - The knight exits the castle after visiting at most \(\max\{n-1, 2n-4\}\) halls.
   - Since \( 2n-4 \) is always greater than or equal to \( n-1 \) for \( n \geq 2 \), the maximum number of halls visited is \( 2n-4 \).

The final answer is \( \boxed{ \max\{n-1, 2n-4\} } \).