Ping Reply Tracking
Updated
Problem statement
Track replies to a finite set of ping echo requests. For this exercise, assume request i is sent at integer time sendTimes[i] and carries the unique identifier i. The request identifiers are 0 through sendTimes.length - 1.
The parallel arrays replyIds and replyTimes describe received echo replies. Reply j names request replyIds[j] and arrives at time replyTimes[j]. The arrays may list replies in any order.
- A reply is eligible only when its identifier names an existing request and its arrival time is in the inclusive interval
[sendTimes[i], sendTimes[i] + timeout]. - Ignore unknown identifiers, replies before a request was sent, and replies after its deadline.
- When several replies are eligible for one request, use the earliest arrival time. Later duplicates have no effect.
Return one integer per request, in request-identifier order. An answered request returns its round-trip time, earliestArrival - sendTimes[i]. A request with no eligible reply returns -1. This exercise supplies the finite send and receive trace; no network access or packet construction is required.
Function
pingRoundTripTimes(sendTimes: int[], replyIds: int[], replyTimes: int[], timeout: int) → int[]Examples
Example 1
sendTimes = [10,20,30]replyIds = [1,0,1,2]replyTimes = [25,17,22,41]timeout = 10return = [7,2,-1]Request 1 chooses time 22 even though its time-25 reply appears earlier in the array. Request 2 times out because 41 is later than its deadline 40.
Example 2
sendTimes = [5,5]replyIds = [0,1,2,0]replyTimes = [4,5,5,5]timeout = 0return = [0,0]With a zero timeout, only replies exactly at the send time qualify. The early reply and unknown identifier are ignored.
Example 3
sendTimes = [100,50]replyIds = []replyTimes = []timeout = 8return = [-1,-1]No received replies means both requests time out, regardless of send-time order.
Constraints
1 <= sendTimes.length <= 10^5.0 <= replyIds.length = replyTimes.length <= 10^5.0 <= sendTimes[i], replyTimes[j] <= 10^9.-1 <= replyIds[j] <= 10^5.0 <= timeout <= 10^6.- Send times need not be sorted or unique.
More NVIDIA Onsite Interview questions
- Check Endianness Of A Byte ArrayONSITE INTERVIEW · Seen Sep 2026
- Implement MallocONSITE INTERVIEW · Seen Sep 2026
- Implement PrintfONSITE INTERVIEW · Seen Sep 2026
- Merge Two Arrays Into Sorted OrderONSITE INTERVIEW · Seen Sep 2026
- Middle Node Of A Linked ListONSITE INTERVIEW · Seen Sep 2026
- Reverse A StringONSITE INTERVIEW · Seen Sep 2026
- Maximum Fish in a GridONSITE INTERVIEW · Seen Sep 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- First Register Overflow TickONSITE INTERVIEW · Seen May 2024
- Two-Egg DroppingONSITE INTERVIEW · Seen May 2024
Similar questions at other companies
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
- Digit-Coded Card ValidationCapital One · ONSITE INTERVIEWCapital One interview questions
- Instant-Runoff Voting WinnerWise · ONSITE INTERVIEW
- Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Online Meeting Scheduler with Fixed RoomsUber · ONSITE INTERVIEWUber interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Simple Bank OperationsOkta · ONSITE INTERVIEWOkta interview questions