Google Interview Question

Given two strings, find if they differ by exactly two letters.

Interview Answers

Anonymous

Sep 2, 2018

What you can do is to have a sliding window where you are checking the different characters inside :-)

Anonymous

Dec 4, 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"

Anonymous

Feb 24, 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; }

Anonymous

Feb 24, 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; }