Google Interview Question for Software Engineers


Country: Switzerland
Interview Type: In-Person




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

We can keep nodes and connections between nodes represents friendship. Each Node can have a hash table of "Liked Things". Such that every time a person likes something, there will be an observer object for all friends. Then the observer checks to see if the "Liked Object" exists in the respective Node's hashtable.

- SK July 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

If two people have common friends, the common friends should be notified if both people like the same thing. So the observer object should iterate through all 2nd degree friends .

- Anonymous July 14, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Person{
	Hashset<Person> friendList = new Hashset<Person>() // like a hashset	
}

class Thing{
	HashSet<Person> LikedBy = new HashSet<Person>();
}

// Now when someone like Thing T , add that person to hashset of T and if likes are greater than friends of person who likes T then iterate through friend list of person and Find if they exists in hashset of T or vice versa

- smarthbehl July 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) The 2nd degree friends of each user can be stored as a HashTreeSet (Ordered Hash Set)
2) The users who have liked each thing can again be stored as a HashTreeSet. Say,

Everytime a thing is liked, get the current sorted list of users who have liked it. Now, do a stepped comparison with the list of 2nd degree friends of the user who has just liked it. If there is matching, then the matched user is sent notification.

- TotalMantella August 22, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You would store the relations in a Graph Database (like Facebook actually does) and attach a trigger to the liking of a page to send a notification to all their friends who also liked that page (really easy to do in a graph database)

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

(1) Use Adjacency Matrix to find out friends
(2) Store Notifications separately in Map with key as Notification ID and value as notification
(3) Now use matrix from point 1 to publish this notification by using Map again with person id as key and set/Queue of notifications as value

- ER.HarvinderSingh May 03, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Distributed database will contain (key, value) pairs, representing the edges in friendship graph.
2. For every things(post) we will keep a observer list(implement observer pattern), containing the list of people who already liked it.
3. Now when a new observer register to the list, loop over existing observers and check from the distributed db which pair is actually friends and send the notification accordingly.

- kzr.buet08 December 20, 2016 | 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