Standard 4 Rounds
Round 1 - Coding (45 mins)
https://leetcode.com/problems/logger-rate-limiter/ (premium)
Finished code in < 10 mins. A lot of time remaining. Disussion regarding doing this for a Stream of messages and other ways to improve the solution for scale.
class Logger {
class Node{
String message;
int timeStamp;
Node(String message, int timeStamp) {
this.message = message;
this.timeStamp = timeStamp;
}
}
PriorityQueue<Node> q;
Map<String, Node> map;
/** Initialize your data structure here. */
public Logger() {
q = new PriorityQueue<>((a,b) -> a.timeStamp - b.timeStamp);
map = new HashMap<>();
}
/** Returns true if the message should be printed in the given timestamp, otherwise returns false.
If this method returns false, the message will not be printed.
The timestamp is in seconds granularity. */
public boolean shouldPrintMessage(int timestamp, String message) {
while(!q.isEmpty() && timestamp - q.peek().timeStamp >= 10) {
Node node = q.poll();
map.remove(node.message);
}
if(map.containsKey(message)) {
return false;
} else {
Node node = new Node(message, timestamp);
map.put(message, node);
q.offer(node);
return true;
}
}
}
Time : O(log n)
Space : O(n)
where n is the number of unique messages in given timeframe.Round 2 - Coding (45 mins)
n*n grid. Spend some time trying to come up with a better approach. Couldn't improve on time complexity. Couldn't find a O(log n) approach.Round 3 - Behavioral (45 mins)
Round 4 - System Design (45 mins)
Result : No offer. Interviewers din't get enough signals.
Take away :
Programming was under control. To be honest the questions were far too easy than what I expected.
Need more work on designing skills and "Behavioral".