Distance between country names is calculated using Levenshtein distance. Answers are sorted by D, then alphabetically by Country A and then Country B. Country A always comes before Country B alphabetically. Under L you are shown the length of the border as a hint.
I got the idea from a similar quiz but I can't find it any more
Informally, the Levenshtein distance between two words is the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other.