Zynga Interview Question


Country: United States




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

why we can not do this one, simple basic appreach:
table: USER_FRIENDS
columns: user_id friend_user_id

user_id, friend_user_id columns together will be unique and they both will be FK for USERS table.

is it much compilicated, or will be slow?

- kamoliddin January 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Fried-to-friend can actually be viewed as an un-directed graph/forest with many disconnected components. These disconnected components are set of people who are friend to someone in that component but none of them are friends to people in other component.
Now lets try to apply graph data structure in this case.We represent graphs as either--> a) adjacency list or b) Adjacency matrix or c)incident list or d) incident matrix.

Considering option a - Adjacency list
Each 'person' entry in table will point to list of other 'person' IDs which in turn will point to IDs of their friends.
As the no of friends is very dynamic as well as big, The table friends will have two columns - person ID and friendsList. Column friendList will store BLOB file storing comma separated list of friend person IDs.

- kuldeep.hbti January 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Great method!

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

I think we store all the friends of a person into a xml file in the relational database, for example
A(a) has B(b),C(c),D(d),E(e), where small letter represents a unique key for a person
we store as follow
<a, A, <sex info>, <age>, <some other info>,"b,c,d,e(we make this as xml file as attach it with every person)">
Now when i have to find out weather A' is friend of B' , i just have to find out A' in list and then i look at it's xml file for B' it it present then yes, otherwise no, obviously if A's xml file contain B then B's xml also contain A
similarly update, friend deletion ,addition, etx. can be done very efficiently, because these xml files can be searched parallelly also

- sonesh January 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This results in too much redundant data . If A,B,C are friends then this info is duplicated in files of B and C also apart from originally storing in A's xml.

- kuldeep.hbti January 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about storing a unique user tuple as a record in a table (say user table). Store every unqiue friend combination as a tuple in the sorted order of the friends name in a db. This is purely in terms of RDBMS perspective. - equivalent of storing an edge in a friend network.
On adding a node and set of edges to the network = adding rows to friend tuple table.
Removing nodes and edges = removing rows from friend tuple table.

Cons: is table scalable containing all tuples of friends ?

- random January 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can we do it by this..
Just make generic table that contains two column "name of person" "table name"

where the table name is the name of table which contains the each persons frinds list .With the help of this ,it is easy to track records.

- Anonymous January 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

we'll require 2 tables
1.the first table will contain all user's info where user_id will be primary key
2.in 2nd table the primary key will be referenced twice one will be primary key and second will be friends id

- sunil harak January 18, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about just a one-to-many relationship on users.

User
	String name
	...
	list<Friendship> friends

Friendship
	User friend
	boolean confirmed

- Evan May 14, 2013 | 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