Given logs when people enter and leave
return who was there at each interval
input:
name | start_time | end_time
Abby 10 100
Ben 50 70
Carla 60 90
Bob 110 120output:
start_time | end_time | names
10 50 Abby
50 60 Abby, Ben, Carla
60 70 Abby, Ben, Carla
70 90 Abby, Carla
90 100 Abby
110 120 BobClarifications:
NxN chess board
N-1 rooks already stay on board so that no one hitting each other. more formally:
no row contains more than 1 rook
no column contains more than 1 rook
place Nth rook, return the position i, j where to place it
but you dont know where current rooks are located
you have a function countRooksInsideRectangle(a,b,c,d) that returns number of rooks within rectangle formed by horizontals a, b (a<=b) and verticals c, d (c<=d)
example
n=3
countRooksInsideRectangle(2,3,1,3) -> 2
countRooksInsideRectangle(1,1,1,1) -> 0
answer: (1,1) (since board is 1-indexed)
chat logs processor
implement two methods
registerEvent(sender, receiver, timestamp)
getMostActiveUser()
activeness is defined as number of chats with other users (at any moment)
i used hashmap<username, hashset>
to keep the active chats for specific user
follow up:
what if we need to return Top K active users
what would we need to change
follow up 2
what if registerEvent is called millions times a day and getMostActiveUser only once a day, what would change
design BookShelfManager class
that has following methods
addBooks(toIndex, books)
removeBooks(fromIndex, toIndex)
moveBooks(fromIndex, toIndex, size)
getBooks()
setBookmarkIndex(index)
getBookmarkIndex()