Ebay Interview Question for Software Engineer in Tests


Country: India
Interview Type: In-Person




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

public static void distinctValue(int[] intArray) {
		Set<Integer> duplicates = new HashSet<Integer>();
		Set<Integer> distinctValues = new HashSet<Integer>();

		for (int element : intArray) {
			if (duplicates.contains(element)) {
				distinctValues.add(element);
			}
			duplicates.add(element);
		}

		System.out.println(distinctValues);

	}

- RajKP August 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think the if condition should be : -

if(!duplicates.contains(element))

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

import java.util.*;
public class Main {
	public static ArrayList<Integer> findDuplicates(int[] array, int max, int min) {
		int[] temp = new int[max - min + 1];
		ArrayList<Integer> duplicates = new ArrayList<>();
		for (int num: array) {
			if (temp[num - min] > 0) {
				duplicates.add(num);
			} else {
				temp[num - min]++;
			}
		}
		if (duplicates.isEmpty()) return new ArrayList<>();
		return duplicates;
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] array = new int[n];
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int num = in.nextInt();
			max = Math.max(max, num);
			min = Math.min(min, num);
			array[i] = num;
		}
		System.out.println(findDuplicates(array, max, min));
	}
}

- Anonymous August 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void Main()
{
int [] arr = new int[10]{1,2,4,5,3,6,7,9,8,10};

int [] distVal = new int[10];
int count = 0;

for (int i = 0; i < arr.Length; i++)
{
for (int j = i+1; j < arr.Length; j++)
{
if (arr[i] == arr[j])
{
distVal[count] = arr[i];
count++;
}
}
}

for (int i = 0; i < distVal.Length; i++)
{
if (distVal[i] != 0)
Console.WriteLine(distVal[i]);
}


}

- Newbie September 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<conio.h>
void main()
{


int a[8]={1,2,1,3,1,4,8,4};
int i,j,k,c=0;
clrscr();
for(i=0;i<=7;i++)
{
if(a[i]==0)
{
i++;
}

for(j=i+1;j<=7;j++)
{
if(a[i]==a[j])
{
a[j]=0;
c++;
}

}
if(c!=0)
{


}
else
{
if(a[i]==0)
{
}
else
{

printf("%d ",a[i]);
}
}
c=0;

}
getch();

}

- an September 15, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int[] findDistinctValue(int[] array){
		
		int distinctValue[];
		HashSet<Integer> distinct = new HashSet<Integer>();
		int lengthOfArray = array.length;
		
		if ( lengthOfArray == 0 || lengthOfArray == 1 ){	
			distinctValue = new int[0];
			return distinctValue;			
		}
		
		
		for(int each : array){
			if (!distinct.contains(each)){
				distinct.add(each);
			}
		}
		
		if (distinct.size() == lengthOfArray){
			distinctValue = new int[0];
			return distinctValue;
		}
		
		distinctValue = new int[distinct.size()];
		int iterator = 0;
		for (int each : distinct){
			distinctValue[iterator] = each;
			iterator++;
		}
	
	return distinctValue;
	}

- Krishna Chaitanya November 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package find.duplicate.value;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FindDuplicateValue {
public static void main(String[] args) {
int[] array = { 6, 7, 3, 3, 3, 4,4,456,22,33,456,7,6,7,6,7,6, 5 };
System.out.println(findDuplicate(array));
}

public static List findDuplicate(int[] array){
boolean moreThanTwo = false;
Arrays.sort(array);
ArrayList<Integer> duplicate=new ArrayList<Integer>();
for(int i=0; i<array.length-1;i++){
if(array[i]==array[i+1]){
if(moreThanTwo){
duplicate.add(array[i+1]);
}
else{
duplicate.add(array[i]);
duplicate.add(array[i+1]);
moreThanTwo=true;
}
}
else
moreThanTwo=false;
}
return duplicate;
}
}

- Walter Chen March 28, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
public class DuplicatesOfArray {
	public static void distinctValue(int[] intArray) {
		HashMap<Integer,Integer> hmap = new HashMap<Integer,Integer>();
		ArrayList<Integer> list = new ArrayList<Integer>(intArray.length);
		for(int i=0;i<intArray.length;i++){
			hmap.put(intArray[i],0);
		}
		for(int i=0;i<intArray.length;i++){
		    if(hmap.get(intArray[i])==0){
		    	hmap.put(intArray[i],1);
			}
		    else if(hmap.get(intArray[i])==1){
		    	hmap.put(intArray[i],2);
		    	list.add(intArray[i]);		    	
		    }		    	
		}
			System.out.println(list);
		}
	public static void main(String args[]){
		DuplicatesOfArray implementation=new DuplicatesOfArray();
		int[] a={1,1,2,2,2,3,4,5,6,6,6,7,7};
		implementation.distinctValue(a);
	}
}

- Saikrishnan January 06, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

package javaprograms;

import java.util.HashSet;
import java.util.Set;

public class Distinctvalues {

public static void main(String[] args) {

int a[] ={3,4,3,4,5,6,7};
Set dup = new HashSet();
Set distinct = new HashSet();
//dup.add(a[0]);
for(int i : a)
{

if(dup.contains(i))

{
distinct.add(i);
}
dup.add(i);
}

System.out.println(dup);
System.out.println(distinct);
dup.removeAll(distinct);
System.out.println(dup);
}

}

- Anonymous January 26, 2016 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

int a[] ={3,4,3,4,5,6,7};

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

package javaprograms;

import java.util.HashSet;
import java.util.Set;

public class Distinctvalues {

public static void main(String[] args) {

int a[] ={3,4,3,4,5,6,7};
Set dup = new HashSet();
Set distinct = new HashSet();
//dup.add(a[0]);
for(int i : a)
{

if(dup.contains(i))

{
distinct.add(i);
}
dup.add(i);
}

System.out.println(dup);
System.out.println(distinct);
dup.removeAll(distinct);
System.out.println(dup);
}

}

- Anonymous January 26, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package javaprograms;

import java.util.HashSet;

import java.util.Set;

public class Distinctvalues {

	public static void main(String[] args) {
		
		int a[] ={3,4,3,4,5,6,7};
		Set dup = new HashSet();
		Set distinct = new HashSet();
		//dup.add(a[0]);
		for(int i : a)
		{
			
				if(dup.contains(i))
					
				{
					distinct.add(i);
				}
				dup.add(i);	
		}
		
		System.out.println(dup);
		System.out.println(distinct);
		dup.removeAll(distinct);
		System.out.println(dup);
	}

}

- Anonymous January 26, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package javaprograms;

import java.util.HashSet;
import java.util.Set;

public class Distinctvalues {

	public static void main(String[] args) {
		
		int a[] ={3,4,3,4,5,6,7};
		Set dup = new HashSet();
		Set distinct = new HashSet();
		//dup.add(a[0]);
		for(int i : a)
		{
			
				if(dup.contains(i))
					
				{
					distinct.add(i);
				}
				dup.add(i);	
		}
		
		System.out.println(dup);
		System.out.println(distinct);
		dup.removeAll(distinct);
		System.out.println(dup);
	}

}

- india January 26, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int a[] ={3,4,3,4,5,6,7};

- Anonymous January 26, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package javaprograms;

import java.util.HashSet;
import java.util.Set;

public class Distinctvalues {

public static void main(String[] args) {

int a[] ={3,4,3,4,5,6,7};
Set dup = new HashSet();
Set distinct = new HashSet();

for(int i : a)
{

if(dup.contains(i))

{
distinct.add(i);
}
dup.add(i);
}

System.out.println(dup);
System.out.println(distinct);
dup.removeAll(distinct);
System.out.println(dup);
}

}

- hospet83 January 26, 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