Given two strings, find if they differ by exactly two letters.
Réponses aux questions d'entretien
Utilisateur anonyme
2 sept. 2018
What you can do is to have a sliding window where you are checking the different characters inside :-)
Utilisateur anonyme
4 déc. 2018
For the sliding window, that works when the characters are "replaced".
Example:
"abcde"
"abcxx"
However, I believe the question must be specified more specifically. If removal of characters is legal, and the removal of one character is still considered "differing" by one character, then the sliding window solution gets more complicated:
Example:
"abcde"
"cde"
Utilisateur anonyme
24 févr. 2019
public static boolean twoLetterDiference(String a, String b){
if(a.length() != b.length())
return false;
HashMap mapA = new HashMap();
HashMap mapB = new HashMap();
for(int i = 0; i mB)
dif += mA-mB;
}
return dif == 2;
}
Utilisateur anonyme
24 févr. 2019
public static boolean twoLetterDiference(String a, String b){
if(a.length() != b.length())
return false;
HashMap mapA = new HashMap();
HashMap mapB = new HashMap();
for(int i = 0; i mB)
dif += mA-mB;
}
return dif == 2;
}