Pergunta de entrevista da empresa Google

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

Respostas da entrevista

Sigiloso

2 de set. de 2018

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

Sigiloso

4 de dez. de 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"

Sigiloso

24 de fev. de 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; }

Sigiloso

24 de fev. de 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; }