## PayPal Interview Question for Software Engineer / Developers

• 0

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

i think there is no need of hash table u can pick a number from first array and serarch for its negative in other arry.. it will run in o(nlogn) time

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

yeah i think this will do, but u ll have to sort the othr array which u ll be using for lookups....

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

Insert all the elements of the first array into the hash table.
Now take each element from the second array subtract from the sum and then look for that number in hash
If found then they are the pair

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

second part of Question is not clear

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

@dashdash is there any other solution to the problem except hashtables?

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

Let arr be the given array.
And K be the give sum

for i=0 to arr.length - 1 do
hash(arr[i]) = i // key is the element and value is its index.
end-for

for i=0 to arr.length - 1 do
if hash(K - arr[i]) != i // if K - ele exists and is different we found a pair
print "pair i , hash(K - arr[i]) has sum K"
end-if
end-for

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

Let arr be the given array.
And K be the give sum

for i=0 to arr.length - 1 do
hash(arr[i]) = i // key is the element and value is its index.
end-for

for i=0 to arr.length - 1 do
if hash(K - arr[i]) != i // if K - ele exists and is different we found a pair
print "pair i , hash(K - arr[i]) has sum K"
end-if
end-for

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

Algo:
1. move the contents of both the arrays to a single array
2. sort this array
3. navigate to that section of the array where -ve moves over to +ve (use the tip that n+(-n)=0). - have two pointers x and y moving in opposite direction to each other
4. if x and y are pointing to absolute of the same number, print the numbers as they add up to 0
5. else move either of that pointer which is pointing to the smaller of the abs of the current number
6. repeat step (4) until x and y are within the range of the array index

Tips:
- use an efficient algo to sort the array
- if there is a 0 which means x & y point to the same number. in this case, move x & y one step away from each other (0 added to any non-zero number will not yield a 0 anyway)

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

find pairs *ONE FROM EACH ARRAY*, that sum to 0.
your solutions loses this key information.

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.