Company: Snapchat
Level: l4
Round: Technical Phone Screen
Overview: This was the first interview a coding interview with an engineer. We spent about 10 minutes on behavioral interview questions.
Question: LogAnalyzer
Description: Essentially a filtering array of log objects that fall within a certain window.
The problem was something like this. I had to ask clarifying questions to get this overview
/**
* Coding Challenge: LogAnalyzer
* You are building a tiny LogAnalyzer class.
*
* The class has two public methods:
* 1. ingest(log: Log): void
* - Stores the log.
* 2. getHottestService(windowTs: number): string
* - Returns the hottest service within the given time window.
*
* Log format:
* {
* serviceId: string;
* timestamp: number; // increasing numeric timestamp
* level: "INFO" | "WARN" | "ERROR";
* }
*
* Log level weights:
* ERROR = 3
* WARN = 2
* INFO = 1
*
* The hotter a service is, the higher the sum of its log weights
* within the specified time window.
*
* If multiple services have the same score, you may decide how to break ties (document your choice).
*/
// Example
// Example 1:
const la = new LogAnalyzer();
la.ingest({ serviceId: "svc-a", timestamp: 1, level: "ERROR" }); // 3
la.ingest({ serviceId: "svc-b", timestamp: 2, level: "WARN" }); // 2
la.ingest({ serviceId: "svc-a", timestamp: 3, level: "ERROR" }); // 3
la.ingest({ serviceId: "svc-a", timestamp: 4, level: "WARN" }); // 2
la.ingest({ serviceId: "svc-b", timestamp: 5, level: "ERROR" }); // 3
// Suppose latest timestamp = 5
// windowTs = 5 → consider timestamps >= (5 - 5) = 0 (all logs)
//
// svc-a score = 3 + 3 + 2 = 8
// svc-b score = 2 + 3 = 5
//
// Expected: "svc-a"
const hottest = la.getHottestService(5);
console.log(hottest); // "svc-a"
The challenging aspect:
- logs can be ingested out of order
- hardest need to figure out which logs fall in the current window.
Uber and few other companies tend to ask fullstack/backend roles like to ask this as a rate limiting problem as well like this. Here’s another variation of the question.
Implement a rate limiter to determine if each request exceeds the maximum number of requests within a window, based on a series of request timestamps.
The implementation should meet the following criteria:
- The input consists of a list of request timestamps `requestTimestamps`
- the window length `windowLength`
- the maximum number of requests `maxRequests`
Return a list of booleans indicating whether each request passes the limit.
Example 1:
requestTimestamps = [1, 2, 3, 4, 5, 6]
windowLength = 3
maxRequests = 2
Output: [True, True, False, True, True, False]