using System.Collections.Generic;
public static void Main()
var Text = "substring1 is the substring2 document that was processed electronically";
var words = Text.Split(" ").OrderBy(x => x).Distinct().ToList();
var patterns = new List<string> { "substring1", "substring2", "substring3", "substring4", "substring5" };
List<string> matches = new();
int patternIdx = 0, wordsIdx = 0;
while(patternIdx < patterns.Count && wordsIdx < words.Count)
int comparision = string.Compare(patterns[patternIdx], words[wordsIdx]);
case > 0: wordsIdx++; break;
case < 0: patternIdx++; break;
matches.Add(patterns[patternIdx]);