using System; using System.Linq; using System.Collections.Generic; public class Test { public static void Main() { HashSet allWords = new HashSet { "flame", "flaming", "flamingo", "funfair", "unfair" }; var query = allWords .Select(word => word.Substring(0, word.Length - 1)) .Concat(allWords.Select(word => word.Substring(1, word.Length - 1))) .Where(candidate => allWords.Contains(candidate)); foreach (string word in query) { Console.WriteLine(word); } } }