Uses Trie Data Structure to find the longest prefix