algorithm - Design a logging system for something like Google, to get the frequency of a URL being clicked in a specified timeframe -


hi question 1 of interviews careercup.

problem statement : how design logging system google , should able query number of times url opened within 2 time frames.

i/p : start_time , end_time , url1 o/p : number of times url1 opened between start , end time.

some specs : database not optimal solution url might have been opened multiple times given time stamp. url might have been opened large number of times within 2 time stamps. start_time , end_time can month apart. time granular second.


my approach:

logging system: build hash table of key url , value arraylist of times when url clicked. query time: when timeframe given, apply modified binary search , positions between timeframe , count number of times url opened between timeframe

can please comment on approach or suggest better approach. thanks.

p.s. have had @ (information retrieval :url hits in time frame) did not find helpful asking again.

i have approached problem below-

storage

i use hashmap having key ---> url value ---> arraylist of date

every time url clicked, add/update entry in hashmap above.

retrieval

for given timeframes t1 & t2 , url, arraylist corresponding url , find positions of t1 & t2. have counter increment until t2 reached.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -