Company: Paytm

Difficulty: medium

Problem Statement

You are given heartbeat records. Each record has: timestamp (in seconds) when the heartbeat was recorded, and service ID it came from. For each service ID, order its heartbeats by timestamp. If the gap between any two consecutive heartbeats is greater than the threshold, that service timed out at least once. Return an array of strings with the service IDs that timed out at least once. The array must be sorted in lexicographical order. Note: Heartbeats are not sorted by timestamp in the input. Example 1 Input: timestamp = [10, 20, 80, 10, 65] serviceId = ["svc1", "svc1", "svc1", "svc2", "svc2"] threshold = 30 Output: ["svc1", "svc2"] Explanation: For svc1: heartbeats at 20s and 80s are 60 seconds apart → exceeds threshold = 30 → timed out. For svc2: heartbeats at 10s and 65s are 55 seconds apart → exceeds threshold = 30 → timed out. Example 2 Input: timestamp = [1, 2, 3] serviceId = ["svc1", "svc2", "svc1"] threshold = 1 Output: ["svc1"] Explanation: For svc1: heartbeats at timestamps 1

More Paytm OA questionsInterview experiences