PayPal Interview Question for Software Engineer / Developers






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

Put items in a hash table one by one. If any item repeats then dont put it. Give back the hash table. Its uniques

- sati June 30, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why not HashSet

- Puru April 15, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

4 ways

1)hash table....
2)sorting
3)two loops
4) if range is known then after visiting every element, mark it visited either by changing its sign or doubling it...

- Anonymous May 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use STL set to uniquely create a set and remove duplicate element from the array

- itcecsa May 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Build a Binary Search Tree.

- Anonymous May 31, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Construct a list
(see list::unique on cplusplus.com)

double mydoubles[]={ 12.15, 2.72, 73.0, 12.77, 3.14,
12.77, 73.35, 72.25, 15.3, 72.25 };

list<double> mylist (mydoubles,mydoubles+10);

mylist.sort(); // 2.72, 3.14, 12.15, 12.77, 12.77,
// 15.3, 72.25, 72.25, 73.0, 73.35

mylist.unique(); // 2.72, 3.14, 12.15, 12.77
// 15.3, 72.25, 73.0, 73.35

- gmoney June 15, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

dont post inbuilt solutions like wit STL .. no company wants us to code with predefined functions..they jus wanna code from scratch..STL map is implemented wit balanced BST..complexity wud obviously be O(n log n)

- siva August 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use idea of counting sort

- Anonymous October 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// Arr = initial array, Len = initial array length, pRes = pointer to the result array, resLen = length of the result array

template <class T>
void RemoveDuplicatesFromArray(T Arr[], T Len, T*&pRes, T&ResLen)
{
	int i;
	bool bExists;
	T* pCurrent;

	if(Len==0)
	{
		pRes=NULL;
		ResLen=0;
		return;
	}

    pRes = new T[Len]; 

	// Always put the first element
	*pRes = Arr[0];
	ResLen=1;

	// then check the result array - do we already have such element?
	for(i=1;i<Len;i++)
	{
		pCurrent = pRes;
		bExists=false;

		do
		{
			if(*pCurrent == Arr[i])
			{
				bExists=true; // found the same element in result array
				break;
			}
			pCurrent++;
		} while(pCurrent < pRes+ResLen);

		if(bExists==false)
		{
			*pCurrent = Arr[i]; // add the element to the result array
			ResLen++;
		}
	} // end of "for"
}

- sergey.a.kabanov January 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In an array of char:

std::string removeDuplicateChar(const std::string& str)
{
	std::string result;
	typedef std::bitset<__SCHAR_MAX__ * 2U + 1> Bitset;
	Bitset bitset;

	std::string::const_iterator it = str.begin(), end = str.end();
	for (; it != end; ++it)
	{
		Bitset::reference ref = bitset[*it];
		if (!ref)
		{
			result += *it;
		}

		ref = 1;
	}

	return result;
}

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

import java.util.*;

class deldupchar
{
public static void main(Srtring[] args)
{
ary a={1,3, 6, 67, 3, 5 , 8};
Arrays.sort(a);// a={1,3,3,5,6,8,67}
for(int i=0;i<a.length-2;i++)
{
if(a[i]==a[i+1])
{
if((i+2)!=a.length+1)
{
a[i+1]=a[i+2];
}
a[i+1]=NULL;
}
}
}

- kruthi August 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.linus.interview.algo;

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

public class RemoveDuplicates {

/**
* @param args
*/
public static void main(String[] args) {
int[] arr = { 1, 3, 4, 1, 2, 6, 2, 3, 33, 11, 33, 4, 99 };
removeDuplicates(arr);
}

private static void removeDuplicates(int[] arr) {
int[] temp = new int[arr.length];
List<Integer> list = new ArrayList<Integer>();
int j=0;
for (int i = 0; i < arr.length; i++) {
if (list.contains(arr[i])) {
} else {
list.add(arr[i]);
temp[j]=arr[i];
j++;
}
}
arr=temp;
//this is only for printing
for(Integer i : arr){
System.out.println(i);
}
}

}

- Sunil Kumar Tamoli September 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ArrayList is the solution. HashSet can be used too, but AL is faster a bit.

public static void main(String[] args) {
		int[] arr = { 1, 3, 67, 3, 6, 88, 9, 56, 4, 5, 7, 23, 4, 99 };
		removeDuplicatesUsingAL(arr);
//		removeDuplicatesUsingHashSet(arr);
	}

	public static void removeDuplicatesUsingAL(int[] arr) {
		long startTime = System.nanoTime();
		System.out.println("Start time: " + startTime);
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < arr.length; i++) {
			if (!list.contains(arr[i])) {
				list.add(arr[i]);
			}
		}

		for (Integer i : list) {
			System.out.println("values are: " + i);
		}
		long endTime = System.nanoTime();
		System.out.println("End time: " + endTime);
		System.out.println("total Time is: " + (endTime - startTime));
	}

	public static void removeDuplicatesUsingHashSet(int[] arr) {
		long startTime = System.nanoTime();
		System.out.println("Start time: " + startTime);
		Set hashSet = new HashSet();
		for (int i = 0; i < arr.length; i++) {
			if (!hashSet.contains(arr[i])) {
				hashSet.add(arr[i]);
			}
		}

		Iterator iter = hashSet.iterator();
		while (iter.hasNext()) {
			System.out.println("values are: " + iter.next());
		}
		long endTime = System.nanoTime();
		System.out.println("End time: " + endTime);
		System.out.println("total Time is: " + (endTime - startTime));
	}

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

using Systems;
using Systems.Collections.Generic;

class sample
{
	public static void Main()
	{
		int[] arr={1,2,3,1,2,3,1,4,5};
		Dictionary<int,int> dict=new Dictionary<int,int>();
		foreach(var a in arr)
		{
			if(!dict.ContainsKey(a))
			dict.Add(a,1);
		}
		foreach(var a in dict)
		{
			Console.Write(a.Key+" ");
		}
		
	}
}

- Roshan Halwai October 09, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

write like this...

Set<T> mySet = new HashSet<T>(Arrays.asList(someArray));

- javid.anees November 26, 2015 | 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