torque on a current loop that is perp to the mag field is
τ = N I A B where N is the number of turns.
In your case, the wire is wrapped into N square turns, with each turn a square of side length
s = L / 4N (each square has perimeter of L/N and the side is 1/4 of the perimeter)
So the area is A = s2 = L2 / 16N2 now sub this into the torque expression and
τ = N I A B = N I (L2 / 16N2 ) B = I L2 B / 16 N
notice that torque is inv prop to N... so the greater the N, the
less the torque. Therefore the greatest torque will be with the
smallest N, or N = 1
Then τ = I L2 B / 16