Twitter Interview Question for Data Engineers

Country: United States

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

This is nothing but LRU cache.

- steep August 29, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

What are we designing for? Space? Time?

If space is available and we can keep all data:

Solution #1
 - Simple solution keep sorted list O(nlogn)
 - return proper slice of list for the queried time O(logN)

Solution #2
 - Create BST and insert into tree O(logN)
 - return subtree whos time is less than the queried time O(logN)

If for space, assume were feed the hashtags one at time

Solution #1
 - N = 10
 - Create three sorted bins of size N elements. For 1min, 10min, 1hr
 - create helper function refresh:
   - In bin1Min, remove expired items, and bubble up to bin10Min or bin1hr  if applicable
   - in bin10Min, remove expired items, and bubble up to bin1hr if applicable
   - in bin1hr, remove expired items.
 - on insert
   - call refresh()
   - insert new item into proper bin based on current time difference
    - find insert position( selection sort since N is small )
    - if over threshold of elements, insert new item in front, and pop last
    - if poped, bubble up if applicable

Do you guys think the above solution would work? Would love some feedback.

- tnutty2k8 August 29, 2017 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


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


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