Level: Senior-Level
Round: Full Journey · Type: Coding · Difficulty: 7/10 · Duration: 180 min
Topics: Data Structures, System Design, Algorithms
Location: San Francisco Bay Area
Interview date: 2025-06-30
Got offer: False
Question: Implemented Windowed Map data structure with put and get operations.
Question: Implemented tail -n API to return the last n lines of a file.
Question: Modified word search problem to handle "AND/OR" conditions.
I had to design a data structure called WindowedMap that stores values associated with keys and timestamps. The structure must support inserting values and retrieving values within a specific time window.
class WindowedMap { void put(String key, int value, long timestamp); List<Integer> get(String key, long startTime, long endTime); }
Operations:
put(key, value, timestamp): Insert a value associated with the key at the given timestamp.get(key, startTime, endTime): Return all values associated with the key whose timestamps fall within the inclusive time range [startTime, endTime].Example:
` put("a", 5, 10) put("a", 7, 12) put("a", 3, 20)
get("a", 10, 15) // Returns [5, 7] `
Constraints:
Follow-ups:
List<Integer> getLast(String key, long windowSize) to return values within the last windowSize time units from the most recent timestamp.I needed to implement an API that returns the last n lines of a file, similar to the Unix command tail.
List<String> tail(String filePath, int n);
Example:
` File contents: line1 line2 line3 line4 line5
tail(file, 2) // Returns ["line4", "line5"] `
Constraints:
Initially, I thought it was a standard word search problem. The first part, searching for a single word, was standard. However, the second part was different from commonly asked interview questions. I had to handle search strings like: "Hello AND World OR is".