## 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

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

Why not HashSet

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...

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

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

Build a Binary Search Tree.

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

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

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)

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

use idea of counting sort

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"
}``````

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;
}``````

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;
}
}
}

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 {
temp[j]=arr[i];
j++;
}
}
arr=temp;
//this is only for printing
for(Integer i : arr){
System.out.println(i);
}
}

}

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])) {
}
}

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])) {
}
}

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));
}``````

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))
}
foreach(var a in dict)
{
Console.Write(a.Key+" ");
}

}
}``````

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));

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.

### 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.