Problem statement

https://binarysearch.com/problems/Almost-Same-Strings/

Solution

Equal to Leetcode 1554 Strings Differ by One Character.

Complexity

Time and space complexity is O(n*m^2).

Code

class Solution:
    def solve(self, dct):
        n, m = len(dct), len(dct[0])
        cnt = set()
        for word in dct:
            for i in range(m):
                cand = word[:i] + "#" + word[i+1:]
                if cand in cnt: return True
                cnt.add(cand)
                
        return False