using System.Collections.Generic;
public static void Main()
string target = "target";
List<string> myStrings = new List<string>();
myStrings = myStrings.OrderBy(each => Levenshtein(each, target)).ToList();
Console.WriteLine(JsonSerializer.Serialize(myStrings));
private static int Levenshtein(string a, string b)
if (string.IsNullOrEmpty(a))
if (!string.IsNullOrEmpty(b))
if (string.IsNullOrEmpty(b))
if (!string.IsNullOrEmpty(a))
int[,] d = new int[a.Length + 1, b.Length + 1];
for (int i = 0; i <= d.GetUpperBound(0); i += 1)
for (int i = 0; i <= d.GetUpperBound(1); i += 1)
for (int i = 1; i <= d.GetUpperBound(0); i += 1)
for (int j = 1; j <= d.GetUpperBound(1); j += 1)
cost = (a[i-1] != b[j-1])? 1 : 0;
min3 = d[i - 1, j - 1] + cost;
d[i, j] = Math.Min(Math.Min(min1, min2), min3);
return d[d.GetUpperBound(0), d.GetUpperBound(1)];