Pregunta de entrevista de Google

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

Respuestas de entrevistas

Anónimo

10 de may de 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 :)

Anónimo

3 de ago de 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.