PayPal Interview Question for Software Engineer / Developers






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

- ankur August 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- fire and ice August 14, 2012 | Flag
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

- DashDash October 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

second part of Question is not clear

- praveen January 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- fire and ice August 14, 2012 | Flag
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

- Rohit June 13, 2013 | Flag Reply
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

- rohit.in.muzik June 13, 2013 | Flag Reply
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)

- ritz December 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Bevan May 17, 2013 | Flag


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