Letters that occur most with other letters in a list of multiple words.
Anonymous User
1700

I was asked this question recently in a startup phone screen.

Given a list of strings/words, return a list/table of all the letters found in multiple strings where it’s occurring most with other letter or letters.

Example:

Input: ["abef", "bcd", "bde", "cadf"]

Output:
[
 a: {f} // f occurs 2 times with a
 b: {d,e} // d and e occur 2 times with b
 c: {d} // d occurs 2 times with c
 d: {b,c} // b and c occur 2 times with d 
 e: {b} // b occurs 2 times with e 
 f: {a} // a occurs 1 time with f
]

How would you go about solving this? Any pointers to similar questions on leetcode?
Update: I proposed having 256x256 ASCII occurrence/adjacency matrix and implemented the solution halfway. In the end interviewer asked me what if it's an unicode string?

Comments (4)