class Finder: def __init__(self): self.Parent = [i for i in range(26)] def union(self, p, q): self.Parent[self.find(p)] =self.find(q) def find(self, p): if self.Parent[p] != p: return self.find(self.Parent[p]) else: return p class Solution(object): d…