A Leetcode Noob's Solution
Feel free to make optimizations. I just wanted to post this bc i felt proud of myself\n\nclass Solution:\n    def findTheString(self, lcp: List[List[int]]) -> s
Feel free to make optimizations. I just wanted to post this bc i felt proud of myself\n```\nclass Solution:\n    def findTheString(self, lcp: List[List[int]]) -> str:\n        n = len(lcp)\n        alpha = "abcdefghijklmnopqrstuvwxyz" # alphabet\n        alpha_map = {alpha[i]: i for i in range(26)} # needed to find the next letter index after a given letter \n        i_to_letter = {i: "a" for i in range(n)} # we assume best case scenario (every letter is a) and change the index->letter map as we iterate n**2 over lcp\n        \n        for i in range(n):\n            for j in range(i, n):\n                length_too_big = lcp[i][j] > n - j # impossible length\n                pardox_letter =  i == j and not lcp[i][j] # letter at i==j means it has to be a prefix of 1 or more\n                parodox_prefix = lcp[i][j] != lcp[j][i] # the inverse of i, j should be equal, longest prefix from i->n-1 and j->n-1 when i and j swap\n                if length_too_big or pardox_letter or parodox_prefix:\n                    return ""\n                \n                if i_to_letter[i] == i_to_letter[j]:\n                    # if they belong to same letter \n                    if lcp[i][j] == 0:\n                        # we have unmatching characters and need to increase letter ord  of j (we pick j bc its going to create a smaller lexographical word)\n                        nxt_idx = alpha_map[i_to_letter[i]] + 1\n                        if nxt_idx >= 26: \n                            # we cannot create a word that goes past letter z\n                            return "" \n                        i_to_letter[j] = alpha[nxt_idx]\n                    else:\n                        # we have matching characters, then we need to check if the current prefix it forms aligns with the next one\n                        if i + 1 < n and j + 1 < n and lcp[i+1][j+1] != lcp[i][j] - 1: \n                            # the next prefix at location lcp[i+1, j+1] should be one minus the length of the current prefix to make it a valid prefix\n                            return ""\n                else:\n                    # i and j do not belong to same letter\n                    if lcp[i][j]: \n                        # if i and j do not belong to same letter, they cannot have any prefix other than 0\n                        return ""\n                    \n        \n        return "".join([i_to_letter[i] for i in range(n)])\n        \n            \n```
[]