I am getting following
"a" is indeed a prefix of itself? Does the question assume can it only be proper prefix?
Now if I modify the code such that it works only for proper prefixes then it gives the following:
Now both can't be right. Is it possible that I have misunderstood the question? I assume we are finding the longest prefix among all pairs of strings in the given array of strings.