Expedia Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
2
of 2 vote

Create a dictionary out of the second string.
Traverse first string by word and verify if the word is present in the dictionary.
if present then remove it from the dictionary.
else, add the word to the output buffer.

unordered_set<string> dict;
void createDictonary(string str)
{
	istringstream iss(str);
	for (string s; iss >> s;)
		dict.insert(s);
}

void func(string str1, string str2)
{
	createDictonary(str1);

	istringstream iss(str2);
	for (string s; iss >> s;)
	{
		unordered_set<string>::iterator pos = dict.find(s);
		if (pos != dict.end())
			dict.remove(s);

		else
			cout << s << " ";		
	}
	cout << endl;
}

- Orion arm, Laniakea April 30, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

remove(String str1, String str2){
		StringTokenizer st = new StringTokenizer(str2);
		while(st.hasMoreTokens()){
			str1 = str1.replaceFirst(st.nextToken(), "");
		}
		return str1;
	}

- Anonymous April 29, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

str1= "A Statement is a Statement"
str2 = "Statement a"

str1 = str1.split()
str2 = str2.split()
print str1
for words in str2:
if words in str1:
str1.remove(words)

st = ' '.join(str1)
print st

- Roopesh April 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Using Java:

int start = str1.indexOf(str2); 
return str1.replace(str2, "");

- Gulam April 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

remove(String str1, String str2){
		StringTokenizer st = new StringTokenizer(str2);
		while(st.hasMoreTokens()){
			str1 = str1.replaceFirst(st.nextToken(), "");
		}
		return str1;
	}

- stringtokenizer April 29, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
package careerCub;

public class StringRemoving {

public static void main(String[] args) {

String s1="A Statement is a Statement";
String s2="Statement a";
String ss=null;
String[] arr1=s2.split("\\s");
String[] arr2=s1.split("\\s");

int flag=-1;

for(int i=0;i<arr1.length;i++){


for(int j=0;j<arr2.length;j++){


flag=arr2[j].compareTo(arr1[i]);

if(flag==0){
ss=s1.replaceFirst(arr2[j], "");
s1=ss;

break;
}
}


}
System.out.println(s1);


}


}


}

- Zeeshan Ahmed Orange May 03, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class StringRemoving {

	public static void main(String[] args) {
		
		String s1="A Statement is a Statement";
		String s2="Statement a";
		String ss=null;
		String[] arr1=s2.split("\\s");
		String[] arr2=s1.split("\\s");
		
		int flag=-1;
		
	for(int i=0;i<arr1.length;i++){
			
			
		for(int j=0;j<arr2.length;j++){
			
					
			flag=arr2[j].compareTo(arr1[i]);
			
			if(flag==0){
				ss=s1.replaceFirst(arr2[j], "");
				s1=ss;
				
				break;
			}
		}
	
				
	}
	System.out.println(s1);
		
	
	}
	
}

- Zeeshan Ahmed Orange May 03, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// we can keep the list aling with map and keep the 
// iterator into this list instead of the int. (index)
// struct entry {
//  int index;
//  list<entry>::iterator iter;
//  // add forn and get the list.begin()   
//};

bool comp_int(const pair<int, string> &p1, const pair<int, string> &p2) {
    return std::less<int>(p1.first. p2.first);    
}

void remove_second(string &s1, string s2) {
    if(s1.empty() || s2.empty()) {
        return;
    }
    unordered_multimap<string, int> storage;
    typedef unordered_multimap<string, int>::iterator it;
    stringstream ss(s1);
    int index = 0;
    string str;
    while(!ss.eof()) {
        ss >> str;
        //cout << "string is " << str <<"\n";
        storage.insert(pair<string, int>(str, index));
        index += str.length();
    }
    
    ss.str(s2);
    index = 0xFFFFFFFF;
    while(!ss.eof()) {
        ss >> str;
        //cout << "string is " << str <<"\n";
        pair<it, it> pit = storage.equal_range(str);
        if (pit.second == storage.end()) {
            continue;
        }
        it iter = pit.first;
        int index_iter = 0;
        int counter = 0;
        while(iter != pit.second) {
            if (index < iter->second) {
                index = iter->second;
                index_iter = counter;
            }
            counter++;
        }
        iter = pit_first + index_iter;
        storage.erase(iter); 
    }
    
    // now iterate iver the hashmap and then sort the entries by the value
    vector<pair<int, string> > v;
    for(it iter = storage.begin(); it != storage.end(); ++it) {
        v.push_back(pair<int, string>(iter->second, iter->first));
    }
    std::sort(v.begin(), v.end(), comp_int);
    // print the vector
    
}

- ali.kheam July 09, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// This will solution assumes that the str2 contains all the unique tokens
	String function(String str1, String str2) {
                StringTokenizer stringTokenizer = new StringTokenizer(str2);
                while (stringTokenizer.hasMoreTokens()) {
                        str1 = str1.replaceFirst(stringTokenizer.nextToken()+" ", "");
                }
                return str1;
        }

- Kapil July 09, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

O(N + M) Time complexity

var removeStrings = function (str1, str2) {
    var arrayA = str1.split(' ');
    var arrayB = str2.split(' ');
    var hashB = {};
    var result = [];
    for (var i = 0; i < arrayB.length; i++) {
        hashB[arrayB[i]] = 1;
    }
    for (var i = 0; i < arrayA.length; i++) {
        if (hashB[arrayA[i]] === undefined) {
            result.push(arrayA[i]);
        }
        else {
            hashB[arrayA[i]] = undefined;
        }
    }
    $(result);
}

- maksymas July 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

str1= "A Statement is a Statement"
str2 = "Statement a"
l1 = list(str1.split(" "))
l2 = list(str2.split(" "))
res = list(filter(lambda x: l1.remove(x), l2))
r = ' '.join(l1)
print(r)

- Vinita October 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def remove_words(str1, str2):
    str1 = str1.split()
    str2 = str2.split()
    for words in str2:
        if words in str1:
            str1.remove(words)
    str1 = " ".join(str1)
    return str1


print(remove_words("A Statement is a Statement", "Statement a"))

- Enthrayu January 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

str1= "A Statement is a Statement"
str2 = "Statement a"

str1 = str1.split()
str2 = str2.split()
print str1
for words in str2:
if words in str1:
str1.remove(words)

st = ' '.join(str1)
print st

- roopi.nudi April 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Using Java:

public static String remove(String str1, String str2){
		int start = str1.indexOf(str2);
		return str1.replace(str2, "");
	}
	public static void main(String[] args) {
		System.out.println(remove("A Statement is a Statement", "a Statement"));
	}
}

- Gulam April 25, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More