I have this levenstein algorithm:

```
public static int? GetLevenshteinDistance(string input, string output, int maxDistance)
{
var stringOne = String.Empty;
var stringTwo = String.Empty;
if (input.Length >= output.Length)
{
stringOne = input;
stringTwo = output;
}
else
{
stringOne = output;
stringTwo = input;
}
var stringOneLength = stringOne.Length;
var stringTwoLength = stringTwo.Length;
var matrix = new int[stringOneLength + 1, stringTwoLength + 1];
for (var i = 0; i <= stringOneLength; matrix[i, 0] = i++) { }
for (var j = 0; j <= stringTwoLength; matrix[0, j] = j++) { }
for (var i = 1; i <= stringOneLength; i++)
{
bool isBreak = true;
for (var j = 1; j <= stringTwoLength; j++)
{
var cost = (stringTwo[j - 1] == stringOne[i - 1]) ? 0 : 1;
matrix[i, j] = Math.Min(
Math.Min(matrix[i - 1, j] + 1, matrix[i, j - 1] + 1),
matrix[i - 1, j - 1] + cost);
if (matrix[i, j] < maxDistance)
{
isBreak = false;
}
}
if (isBreak)
{
return null;
}
}
return matrix[stringOneLength, stringTwoLength];
}
```

I checked each values and if it > max distance I break for. But it does not always work correctly.

For example:

```
string1 = "#rewRPAF"
string2 = "#rewQVRZP"
maxDistance = 4
```

I get value 5 but don't null.

This solution i get this - Levenstein distance limit