Pinterest Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Use a hashtable to store the pin_id <-> score mappings.
Maintain a min heap of the top 50 pins with the highest scores.
Whenever the score of a pin is updated, compare with the score at the root of the heap. If more, pop out the root and push the new pin into the heap.

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

Algo:
Store <pinId, IntegerCount> in a Map.
On every 'like' update the respective count for corresponding pinId. O(1) for update
On every page request, scan the list to obtain 'Top 50'. O(N) to scan for top 50 (use LRU concept to weed out min)

Smarter: As opposed to on every page req and to save on processing, update the top 50 list every N minutes

- Ashish Jain February 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Create a max heap of 50 elements. Also keep a hash for all the elements. Updating the element will take O(1) time. Now once the heap is build, updating the elements or replacing will take constant time.

- DashDash February 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you expalin in more ditail, please

- dadakhalandhar February 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Correcting....create a min heap of 50 elements. Initially after traversing all the million pins we have the top 50 pins in the heap. Now whenever the pin is updated, we can heapify the heap accordingly

- DashDash March 18, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Priority Queue using Heap data struture

- samir March 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I'll maintain top_50_list = []
top_50_list has (score, id) tuple with min score.
e.g. top_50_list = [(888, 12), (992, 28381), ..., (823, 1293)]
min_score = 823
you can make it O(N). N = 10M

Whenever score update happen, this logic
def update(id, score):
if score < min_score:
return

if id in top_k_list: # somehow
# find index i
top_k_list[i] = (score, id)
else:
# delete min_score element
top_k_list.append((score, id))
min_score = min([score for score, id in top_k_list])

- seong December 19, 2019 | 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