trie implementation and max contiguous subsequence calculation