# A complex problem from Garena 2017 challenge [duplicate] The problem is quite complex and I would really like to know the solution.

There is a strategy that allows Bob to correctly find Trent's card with 100% probability. First, Alice and Bob agree on an ordering of the 52 cards. Call this function of card to position $f$. Bob's strategy is to start with card $f(T)$, where $T$ is the card Trent picks, and continue opening $f(f(T))$, and so on. If $T$ is in a cycle of size 26 or less, we win! Otherwise we lose.
Fortunately Alice can control the size of the cycles. Namely, there exists only one cycle at most with size greater than 26. If one exists, Alice can break the cycle into two smaller cycles of equal size via a single swap. For instance, if the cycle is $c_1 \rightarrow c_2 \rightarrow \cdots c_n \rightarrow c_1$, then Alice should swap cards $c_{\lfloor n/2\rfloor}$ and $c_n$. Then the cycles are $c_1 \rightarrow c_2 \rightarrow \cdots c_{\lfloor n/2\rfloor} \rightarrow c_1$ and $c_{\lfloor n/2 \rfloor + 1} \rightarrow c_{\lfloor n/2 \rfloor + 2} \rightarrow \cdots c_n \rightarrow c_{\lfloor n/2 \rfloor + 1}$, with cycle size at most $\lceil n/2 \rceil \leq 26$ Therefore, the final state does not have any cycle of size greater than 26, and the duo is guaranteed a one month salary increase.