Domanda di colloquio di Google

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

Risposte di colloquio

Anonimo

2 set 2018

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

Anonimo

4 dic 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"

Anonimo

24 feb 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; }

Anonimo

24 feb 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; }