Facebook Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

create an array pointers for frequecy max; lets say 10 million
create a trie for all the substring. (or a suffix tree)

The leaf of a trie will contain two variables and two pointers.
one variable contains the time stamp
the other variable contains the frequency.
one pointer contain the address of frequency pointer for k.
the other contain the pointer to the next leaf of the same frequency. (you can even have double linked list).
when a substring is found again, you increase the frequency and change the next leaf pointer
to the leaf containing at the next frequency array pointer.

when you want the N most common substrings for a time frame T.
go through the linked list pointed by the max frequency array pointer till time frame T.
repeat the procedure to the next max frequency.

update substring= O(1)
adding new substring = O(1)
N most freq = O(N)
decrease substring = O(1) (dont update the time stamp while decreaseing freq).

ofcourse you have the time taken for searching string in the trie or suffix tree
which would cost O(P +Sigma) P = length of pattern + max P. which can be obtained
by having weighted balanced search tree at every node in the trie.

if frequency exceeds the max, then create a max frequency array pointer. :)
or if you are worried about the size of frequency array pointer, then create
a frequency bst/heap/wbst etc.

- Anonymous November 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

create an array pointers for frequecy max; lets say 10 million
create a trie for all the substring. (or a suffix tree)

The leaf of a trie will contain two variables and two pointers.
one variable contains the time stamp
the other variable contains the frequency.
one pointer contain the address of frequency pointer for k.
the other contain the pointer to the next leaf of the same frequency. (you can even have double linked list).
when a substring is found again, you increase the frequency and change the next leaf pointer
to the leaf containing at the next frequency array pointer.

when you want the N most common substrings for a time frame T.
go through the linked list pointed by the max frequency array pointer till time frame T.
repeat the procedure to the next max frequency.

update substring= O(1)
adding new substring = O(1)
N most freq = O(N)
decrease substring = O(1) (dont update the time stamp while decreaseing freq).

ofcourse you have the time taken for searching string in the trie or suffix tree
which would cost O(P +Sigma) P = length of pattern + max P. which can be obtained
by having weighted balanced search tree at every node in the trie.

if frequency exceeds the max, then create a max frequency array pointer. :)
or if you are worried about the size of frequency array pointer, then create
a frequency bst/heap/wbst etc.

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

forgot to mention.
you do two updates one to the past window and the other
to the current window. once we cross the current window.
the next window are updates are done to the past window.

- huha November 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

How will you take care of previous timestamps of the same word??

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

heap would work with a mechanism to 'retire' count based on timestamps.

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

this question can take up the entire interview, for instance how to model retweets, authority of people tweeting / retweeting, what about topics not mentioned in tweet and can be inferred from it

- just_do_it March 14, 2015 | 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