This is the Deutsch-Jozsa test with an arbitrary uniform-state unitary, and does not require to be a power of two. Choose a known unitary operator such that . Prepare the target qubit in . One Boolean-oracle call gives quantum phase kickback:
Apply to the index register. The amplitude on is
It equals or for the two constant strings, and equals zero for a balanced string. Consequently a single query decides the promised problem exactly: measure the index register and report constant for outcome zero, balanced for any other outcome. This is the Deutsch-Jozsa algorithm with the available exact state-preparation operation.
Use the available unitaries to prepare
in the first register and
in the answer qubit. The quantum phase kickback identity gives
Choose a unitary with , apply to the first register, and measure it. Its amplitude at is
This equals or for a constant string and zero for a balanced string. Thus outcome means constant, while every other outcome means balanced, with certainty after one oracle query. This is the Deutsch-Jozsa test with an arbitrary uniform-state unitary.