Text this: A Characterization of Optimal Prefix Codes