Interview Question


Country: United States




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

in java

static void findIntersection(String a, String b){
		List<Character> inter = new ArrayList<Character>(); 
		for(int i=0; i< a.length();i++){
			if(b.indexOf(a.charAt(i)) > -1){
				if(!inter.contains(a.charAt(i)))
					inter.add(a.charAt(i));
			}
				
		}
		for(Character c: inter)
			System.out.println(c);
		
	}

- akash.bhunchal January 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

WITHOUT for loops ree

- Kshitij January 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it said " without using 2 for loops". :) ... might be a typo ...

- akash.bhunchal January 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use recursion . use c style arrays. make function as compare(i,j); increment both in recursion . whenever same. store i array. when \0 reached. return . That should do it

- Anonymous January 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can you please write code snippet

- CareerCupUser1 January 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

build a suffix tree (array) of first string, then test the second string ?

- forkloop January 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Does to "without 2 for loops" mean nested for loop ?

- Phani January 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Likely. I suppose it means to solve it in O(n)

- Anonymous January 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

map of one the string in a hashmap, and scan the other one based on the built hashmap. We can get the intersection.

- zhou January 11, 2012 | 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