Determine string buildability from dictionary | Amazon Interview Question