Solution for string similarity problem