fork download
  1. def sum_matching_characters(strings):
  2. n = len(strings)
  3. max_len = max((len(s) for s in strings), default=0)
  4.  
  5. matrix = [[0] * 26 for _ in range(max_len)]
  6. ans = [0] * n
  7.  
  8. for i in range(n - 1, -1, -1):
  9. s = strings[i]
  10. matches = 0
  11.  
  12. for pos, ch in enumerate(s):
  13. matches += matrix[pos][ord(ch) - ord('a')]
  14. ans[i] = matches
  15.  
  16. for pos, ch in enumerate(s):
  17. matrix[pos][ord(ch) - ord('a')] += 1
  18.  
  19. return ans
Success #stdin #stdout 0.08s 7992KB
stdin
Standard input is empty
stdout
Standard output is empty