I.5.4 problem with optimal depth

Hi,
By shorting the H and T gates, I get a depth of 5 but 6 is required and I can’t point my finger on it what is missing. If I understand it correctly:
q0 should have one H gate because ther other cancel eachother out.
q1 has a H gate and a T gate rest cancel eachother out again
and q2 should be H,T,H,T,H because of the sequence only one pair cancel itself out.

Do I have the wrong perspective how the canceling works or what is the problem?

Hello @Cap_Cap! Welcome to the forum!
For this Codercise, note that the T gates don’t cancel each other out. For unitary gates, it is true that U^{\dagger} = U^{-1}. But it is generally not true that U = U^{-1}. This does happen for the Hadamard gate:

H^{\dagger} = H^{-1} = H.

Therefore H\cdot H=\mathbb{I} and you can cancel them. But not for the T gate, in fact T\cdot T =S. This means that if you see two T's together, you can’t just cancel them out. But if you see a T^{\dagger} and a T together, you can.

Hope this helps!

Alvaro