Datadog software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
PacketBuffer class that manages a fixed-capacity in-memory buffer for incoming data. Data is flushed to disk in chunks when the buffer...Input: Stringtimestamp, level, and message. Create a function query_logs(logs: List[Dict[str, Any]], level: str) -> List[Dict[str, Any]] that returns all logs of a specific level. def query_logs(logs: List[Dict[str, Any]], level: str) -> List[Dict[str, Any]]:logs = [
{'timestamp': '2023-10-01T12:00:00Z', 'level': 'info', 'message': 'Service started'},
{'timestamp': '2023-10-01T12:01:00Z', 'level': 'error', 'message': 'Service failed'},
{'timestamp': '2023-10-01T12:02:00Z', 'level': 'info', 'message': 'Service running'}
]
level = 'info'[
{'timestamp': '2023-10-01T12:00:00Z', 'level': 'info', 'message': 'Service started'},
{'timestamp': '2023-10-01T12:02:00Z', 'level': 'info', 'message': 'Service running'}
]info level.logs = [
{'timestamp': '2023-10-01T12:00:00Z', 'level': 'warning', 'message': 'Low disk space'},
{'timestamp': '2023-10-01T12:00:00Z', 'level': 'error', 'message': 'Unauthorized access'},
]
level = 'error'[
{'timestamp': '2023-10-01T12:00:00Z', 'level': 'error', 'message': 'Unauthorized access'}
]error level only.None. The function should return the latest timestamp and its corresponding value for that service.def latest_metric(metrics: List[Tuple[str, str, float]], service_name: str) -> Optional[Tuple[str, float]]:latest_metric([('2023-01-01T12:00:00', 'serviceA', 1.0), ('2023-01-01T12:05:00', 'serviceA', 1.5), ('2023-01-01T12:02:00', 'serviceB', 0.5)], 'serviceA')('2023-01-01T12:05:00', 1.5)serviceA is from 2023-01-01T12:05:00 with a metric value of 1.5.latest_metric([('2023-01-01T12:00:00', 'serviceA', 1.0)], 'serviceB')NoneserviceB.find_metrics_frequency that returns a dictionary recording the frequency of each metric within that time frame. If a metric appears more than once, it should be counted accordingly.def find_metrics_frequency(metrics: List[str], time_frame: int) -> Dict[str, int]:metrics = ['cpu', 'memory', 'cpu', 'disk', 'memory'], time_frame = 5 {'cpu': 2, 'memory': 2, 'disk': 1} metrics = ['requests', 'errors', 'errors', 'cpu'], time_frame = 4 {'requests': 1, 'errors': 2, 'cpu': 1} 1 <= len(metrics) <= 10^6 MetricsMonitor to handle the storage and retrieval of metrics. The system should support adding metrics, retrieving the average of a metric over a specified time window, and removing metrics older than a given time. The add_metric function should store metrics with a timestamp, while the get_average should compute the average of metrics in the specified time window created from a given timestamp. The remove_old_metrics will eliminate metrics older than a certain threshold.Function/class signature: def add_metric(name: str, value: float, timestamp: int) -> None: def get_average(name: str, current_time: int, time_window: int) -> float: def remove_old_metrics(current_time: int, threshold: int) -> None: add_metric("cpu_usage", 30.5, 1609459200) None get_average("cpu_usage", 1609459260, 300) 30.5 0 < timestamp <= 10^9 -1000 <= value <= 1000 0 < time_window <= 3600 10^6 metrics.buckets, and a bucket_width. Your task is to calculate how frequently each range of latencies occurs. Each bucket covers a width of bucket_width. For example, if the latencies are [10, 20, 30, 20, 15], buckets is 5, and bucket_width is 10, your output should reflect the count of latencies that fall within the respective ranges (0-10, 10-20, etc.).def calculate_latency_buckets(latencies: List[int], buckets: int, bucket_width: int) -> List[int]:latencies = [10, 20, 30, 20, 15], buckets = 5, bucket_width = 10 [1, 3, 1, 0, 0] latencies = [1, 12, 25, 3, 30], buckets = 5, bucket_width = 10 [2, 1, 1, 1, 0] window size (in seconds), then returns the statistics over the last specified window size for each event. The statistics should include the sum, count, and average of the events within the time window, inclusive of the current event.def calculate_statistics(events: List[Tuple[int, float]], window_size: int) -> List[Tuple[float, int, float]]: [(1, 10), (2, 20), (3, 30), (4, 40)], window_size=2 [(10.0, 1, 10.0), (30.0, 2, 15.0), (60.0, 3, 20.0), (40.0, 1, 40.0)] [(1, 15), (3, 25), (5, 35)], window_size=3 [(15.0, 1, 15.0), (25.0, 1, 25.0), (35.0, 1, 35.0)]1 <= len(events) <= 10^6 0 <= events[i][0] <= 10^9 0 <= events[i][1] <= 10^9 1 <= window_size <= 10000 timeWindow, return a list of unique metrics that appear in the last timeWindow elements of the list. The result should maintain the order of first appearances in the time window.def unique_metrics(metrics: List[str], timeWindow: int) -> List[str]:metrics = ['cpu', 'memory', 'disk', 'cpu', 'network', 'memory'], timeWindow = 4['disk', 'cpu', 'network', 'memory']metrics = ['cpu', 'cpu', 'memory', 'disk'], timeWindow = 2['memory', 'disk']Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free