A good diagram for your problem is a Right Triangle where the height to the tower window and the distance across the moat form the the legs and Repunzel's hair would be the Hypotenuse, the longest diagonal distance connecting the two legs so the prince can climb up.
The height of the tower 20 m straight up and the moat of 5 m wide form two legs of a Right Triangle, whose Hypotenuse, Repunzel's hair, can be determined with the Pythagorean Theorem.
a2 + b2 = c2 where c is the hypotenuse, the longest side and the connecting diagonal for the prince.
52 + 202 = 425
To find c we need the square root of 425
√425 = 20.62 m of long strong hair to extend diagonally across the moat to the tower window so he can climb up.
I hope this helps, please send me a message if you have any questions.