Conditions for optimal construction of two-qubit nonlocal gates