Given a list of words, each word consists of English lowercase letters.
Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac".
A word chain is a sequence of words [word_1, word_2, ..., word_k] with k >= 1, where word_1 is a predecessor of word_2, word_2 is a predecessor of word_3, and so on.
Return the longest possible length of a word chain with words chosen from the given list of words.
 
Example 1:
Input: ["a","b","ba","bca","bda","bdca"]
Output: 4
Explanation: one of the longest word chain is "a","ba","bda","bdca".

 
Note:

1 <= words.length <= 1000
1 <= words[i].length <= 16
words[i] only consists of English lowercase letters.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'from collections import defaultdict, deque\n\nclass Solution:\n    def longestStrChain(self, words: List[str]) -> int:\n        if len(words) <= 1:\n            return len(words)\n        \n        graph_dict, len_words_dict = self.getGraphDict(words)\n \n        word_lengths = list(len_words_dict.keys())\n        word_lengths.sort()\n        \n        length_index_dict = defaultdict()\n        for i in range(len(word_lengths)):\n            length_index_dict[word_lengths[i]] = i\n        \n        return self.bfsWordChain(graph_dict, len_words_dict, word_lengths, length_index_dict)\n    \n    def bfsWordChain(self, graph_dict, len_words_dict, word_lengths, length_index_dict):\n        word_lenghts_index = 0\n        initial_words = len_words_dict[word_lengths[0]]\n        \n        max_possible_length = len(word_lengths)\n        curr_length = 1\n\n        visited = set()\n        \n        queue = deque()\n        for word in initial_words:\n            queue.append((word, 1))\n            visited.add(word)\n        \n        max_len_so_far = 1\n        \n        while queue:\n            this_item = queue.popleft()\n            this_word = this_item[0]\n            this_chain_len = this_item[1]\n            max_len_so_far = max(max_len_so_far, this_chain_len)\n            this_item_possible_length = this_chain_len + len(word_lengths) - length_index_dict[len(this_word)]\n            if this_item_possible_length > max_len_so_far:\n                neighbors = graph_dict[this_word]\n                for neighbor in neighbors:\n                    if neighbor not in visited:\n                        visited.add(neighbor)\n                        queue.append((neighbor, this_chain_len + 1))\n\n                if len(queue) == 0:\n                    word_found = False\n                    for word_length in word_lengths:\n                        for word in len_words_dict[word_length]:\n                            if word not in visited and not word_found:\n                                queue.append((word, 1))\n                                visited.add(word)\n                                word_found = True\n                                break\n        \n        return max_len_so_far\n            \n        \n        \n\n    \n    def getGraphDict(self, words):\n        len_words_dict = defaultdict(list)\n        for word in words:\n            len_words_dict[len(word)].append(word)\n        word_lenghts_arr = []\n        graph_dict = defaultdict(list)\n\n        for word_length in len_words_dict:\n            for predecessor in len_words_dict[word_length]:\n                if word_length + 1 in len_words_dict:\n                    for word in len_words_dict[word_length + 1]:\n                        if self.isPredecessor(predecessor, word):\n                            graph_dict[predecessor].append(word)\n\n        return graph_dict, len_words_dict\n    \n    def isPredecessor(self, predecessor, word):\n        predecessor_index = 0\n        word_index = 0\n        while predecessor_index < len(predecessor) and word_index < len(word):\n            if predecessor[predecessor_index] == word[word_index]:\n                predecessor_index += 1\n                word_index += 1\n            else:\n                word_index += 1\n        \n        if word_index == predecessor_index + 1 or word_index == predecessor_index:\n            return True\n        else:\n            return False\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'longestStrChain'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 10388