bp interview question

a brave knight DSA problem