Editorial
A quantum gate that swaps the states of qubits is called a swap gate.
In this problem, since only the qubits are swapped and the probability amplitudes remain unchanged, you might consider using an gate or a gate 1.
In fact, it is known that the swap gate can be implemented using three controlled gates, as shown below:

The state transitions can be expressed as follows:
The gate swaps the probability amplitudes of and , while the gate swaps the probability amplitudes of and .
The circuit depth is .
Follow-up
XOR swap is a classical algorithm to swap variables and in steps. This algorithm uses XOR operations to achieve swapping in the following steps:
- Replace with .
- Replace with .
- Replace with .
The operation of replacing with corresponds to , and the operation of replacing with corresponds to , so you can solve this problem based on this algorithm.
Sample Code
Below is a sample program:
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(2)
qc.cx(0, 1)
qc.cx(1, 0)
qc.cx(0, 1)
return qc
Footnotes
-
Refer to the editorial for QPC 001 - A3 for information on controlled gates. ↩