Persistent Systems Interview Question for Java Developers


Country: India
Interview Type: Written Test




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

// ZoomBA
input1 = [ "p","q","r"]  
input2 = [ "p","s","w"] 
intersect = input1 & input2

- NoOne October 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Any of these set sorted?

- Akhil February 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This code will run in O(n) and space complexity O(k) where K = max(arr1.length, arr2.length)

/**
 * Given two char[] arrays of arbitrary length, return the intersection of the arrays
 * Example {'p','q','r'} , {'a','b','c', 'p'}
 * 
 * @author Fayez El-Far
 *
 */
public class IntersectionOfSets 
{
	public List<Character> findIntersection(char[] arr1, char[] arr2)
	{
		if(arr1 == null || arr2 == null) { throw new IllegalArgumentException(); }
		if(arr1.length == 0 || arr2.length == 0) { return null;}
		HashSet<Character> set = new HashSet<>();
		List<Character> intersection = new ArrayList<>();
		//Insert the longer of the two arrays while ensuring not to insert repeated elements more than once
		if(arr1.length >= arr2.length)
		{
			for(int i = 0; i < arr1.length; i++)
				set.add(arr1[i]);
			for(int j = 0; j < arr2.length; j++)
			{
				if(set.contains(arr2[j]))
				{
					if(intersection == null) { intersection = new ArrayList<>();}
					intersection.add(arr2[j]);
				}
			}
		}
		else
		{
			
			for(int i = 0; i < arr2.length; i++)
				set.add(arr2[i]);
			
			for(int j = 0; j < arr1.length;j++)
			{
				if(set.contains(arr1[j]))
				{
					if(intersection == null) { intersection = new ArrayList<>();}
					intersection.add(arr1[j]);
				}
			}
		}
		
		return intersection;	
	}

}

- fayezelfar February 17, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.regex.*;
import java.util.*;
class Intersection
{
public static void main(String args[])
{
String input[]={"p","q","r"};
String input2[]={"p","s","w"};
for(String str:input)
{
Pattern p=Pattern.compile(str);
for(String str2:input2)
{
Matcher m=p.matcher(str2);
while(m.find())
{
System.out.println(m.group());
}
}
}
}
}

- Mazahar December 11, 2016 | 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