Implemented longest_common_prefix