using System.Collections.Generic;
using static System.Console;
public static List<string> Commands { get; } =
public static void Main()
WriteLine(Expand("EXE"));
WriteLine(Expand("hell"));
WriteLine(Expand("hellow"));
WriteLine(Expand("HELLOP"));
public static string Expand(string input)
var candidates = Commands.Where(x => x.StartsWith(input, StringComparison.CurrentCultureIgnoreCase)).ToList();
if (candidates.Count == 0)
if (candidates.Count == 1)
return candidates.First();
var commonPrefix = CommonPrefix(candidates);
return commonPrefix.ToLowerInvariant();
public static string CommonPrefix(IList<string> options)
foreach (char c in options[0])
foreach (string s in options)
if (s.Length <= prefixLength || char.ToUpperInvariant(s[prefixLength]) != char.ToUpperInvariant(c))
return options[0].Substring(0, prefixLength);