working string algo