Question d’entretien chez Google

Given two strings (say string A, string B). Write a function that returns string A - string B.

Réponses aux questions d'entretien

Utilisateur anonyme

10 mai 2010

Look at the problem in the following way. both strings A and B are set of characters so you are looking at set difference string set_difference(string a, string b){ map store; string ret; for(int i=0; i symmetric_diff(vector s1, vector s2){ map store; vector ret; for(int i=0; i by a String that should work!! Cheers :)

Utilisateur anonyme

3 août 2010

here you have O(n^2) complexity and strlen(s2) bytes storage complexity. You can solve this problem with O(n) complexity without any storage requirement. First sort both strings (sorting requires O(nlogn) complexity) Then compare both strings in a loop. This loop requires O(n) complexity.