Pergunta de entrevista da empresa Tinder

1st phonescreen: 1) background 2) algorithmic question which i dont remember but it was average difficulty level 3) Pagination in java - Given an implemented method getFeed(userId, StartTimeStamp, EndTimeTimeStamp) which returns a List<Feed>, right an API to return feeds to a mobile client. Design the API from scratch

Respostas da entrevista

Sigiloso

9 de nov. de 2017

He is right. Below is some rough implementation. To clarify your doubts: 1.) He wants your to use some sort of cache so that calls to getFeed() can be minimized. May be its an RPC call over network. Using cache while doing pagination will help because then we can cache the results of the getFeed(). 2.) He wants backend to `remember` range returned List getPaginatedFeed(String userId, int maxLimit, long startTimeStamp) { List list; if (cache.contains(userId)) { list = cache.get(userId); } else { list = getFeed(userId, startTimeStamp, System.currenttimemillis()); cache(userId, list); countCache.put(userId, 0); } int count = countCache.get(userId); if (list.size() newList = new ArrayList(); for (; count getFeed(String userId, long startTimeStamp, long endTimeTimeStamp) { }

1

Sigiloso

20 de jan. de 2019

Feed needs to be cached by a combo of userId+timestamp Pagination should return a cursor. Some dbs like Dynamo/Elastic can give you out of the box

1

Sigiloso

6 de jul. de 2017

pagination answer: I could only write the API definition as he constantly interrupted me. My initial definition was getMobileFeed(userId, startTS, endTS, startPage, limit). To this he changed the question saying that the Mobile client cannot pass startDate and enddate. I counter questioned him saying that this cannot happen because how would the backend api know what does the client wants. He said, then startTS is allowed, Then he said that client cannot pass pageIndex. I said then how will the backend know about the range. After some more discussion I said that I dont want to use cache because the start and end is always changing and it will never hit the cache. He said all of my answers are wrong and he said I should be using the endTS for the range of pagination