Google Interview Question

Given a list of strings return the substring representing the longest common prefix

Interview Answers

Anonymous

May 14, 2011

Consider inserting the strings into a "trie" and keep track of the longest prefix.

6

Anonymous

Apr 4, 2011

b/w 2 strings -> the brute force method (comapre one by one until they are not equal). divide and conquer the original problem by finding longest common prefix of every 2 strings, then lcp of the found lcps, and so on....

2

Anonymous

Feb 4, 2012

Sort strings first. Then compare each char of n and n+1 keeping track of longest prefix.

1