cpp implementation of Longest Common Prefix