unknown Interview Question for Software Engineer / Developers






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

fun PrintChar(string A , string B){
     bool isPresentInB[128]=false ; // initialize all elements with false
     for(int i=0;i<B.size();i++)isPresentInB[B[i]]=true;
     bool isPresentInAbutNotInB[128]=false;
     for(int i=0;i<A.size();i++)if(!isPresentInB[A[i]]) isPresentInAbutNotInB[A[i]]=true;
  
     for(int i=0;i<128;i++)if(isPresentInAbutNotInB[i]) printf("%c\n",i);
}

- Frodo Baggins August 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

who says you only have 128 chars? :)
anyway...the counting idea is good.

- S August 21, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

temp = String A;
foreach elem in String B {
  if(elem is present in temp) {
    delete elem from temp;
  }
}
print temp;

- Ravi August 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How do you do "is present" and "delete elem"?

- S August 21, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

you can insert all the characters in string B into a hash table, than check every character in string A. It takes linear time.
If you are not conformable with hashing, you can sort A and B respectively and than identify the characters in A but not in B by a scan in a similar way as merge sort.

- Anonymous August 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I've seen hashing mentioned so many times on this site, but no implementation. Can somebody show this in code? I would normally use a set for this purpose, but set in C++ is a red-black tree, thus not really hashing.

- Victor P. August 21, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

+1 for the anonymous solution posted above. I thought of typing the same... Sigh...

- shrikar August 21, 2010 | 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