We design an algorithm to determine the (minimum) T-count of any n-qubit (n ≥ 1) unitary W of size 2n × 2n, over the Clifford+T gate set. The space and time complexity of our algorithm are $$O\left({2}^{2n}\right)$$
O
2
2
n
and $$O\left({2}^{2n{{{{\mathcal{T}}}}}_{\epsilon }(W)+4n}\right)$$
O
2
2
n
T
ϵ
(
W
)
+
4
n
, respectively. $${{{{\mathcal{T}}}}}_{\epsilon }(W)$$
T
ϵ
(
W
)
(ϵ-T-count) is the (minimum) T-count of an exactly implementable unitary U ($${{{\mathcal{T}}}}(U)$$
T
(
U
)
), such that d(U,W) ≤ ϵ and $${{{\mathcal{T}}}}(U)\le {{{\mathcal{T}}}}({U}^{{\prime} })$$
T
(
U
)
≤
T
(
U
′
)
where $${U}^{{\prime} }$$
U
′
is any exactly implementable unitary with $$d({U}^{{\prime} },W)\le \epsilon$$
d
(
U
′
,
W
)
≤
ϵ
. d(. , .) is the global phase invariant distance. Our algorithm can also be used to determine the (minimum) T-depth as well as the minimum non-Clifford-gate count or depth required to implement any multi-qubit unitary with a finite universal gate set like Clifford+CS, Clifford+V, etc. For small enough ϵ, we can synthesize the optimal circuits.