I have a dictionary of words like this -
{"a": {"b": {"e": {},
"f": {},
"g": {"l": {},
"m": {},
"n": {}}},
"c": {"h": {},
"i": {}},
"d": {"j": {},
"k": {}}}}
It's a tree like structure that translates like this
a
/ |\
/ | \
/ | \
/ | \
/ | \
/ | \
b c d
/ | \ | \ |\
e f g h i j k
/ |\
l m n
And I have a list of characters - [a, c, h, q, r]
I want to find if the given word(the list of characters) exist in the dictionary and if it doesn't, return the longest sub-sequence from the beginning that exists. If it does, return the same list.
In the above example, the return should be - [a, c, h]