I was asked two question. Do comment if you have a good solution
- Given a matrix of following relationships between N LinkedIn users (with ids from 0 to N-1):
- followingMatrix[i][j] == true iff user i is following user j
- thus followingMatrix[i][j] doesn't imply followingMatrix[j][i].
- Let's also agree that followingMatrix[i][i] == false.
- An influencer is a user who is:
-
- followed by everyone else and
-
- not following anyone herself/himself
- This method should return the influencer's id in a given matrix of following relationships,
- or return -1 if there is no influencer in this group.
*/
int getInfluencer(boolean[][] followingMatrix);
}
[f t t]
[t f f]
[f f f] - no influencer
[f f t]
[t f t]
[f f f] - 3 is An influencer
- Design a data structure that supports the following in optimal way :
- void add(T val)
- void remove(T val)
- T removeRandomElement() - pick any element randomly and remove it
All operation must be in O(1) time