Katkat

Compute Latencies and Search Grid Path

AmazonSoftware Engineer · Technical Screen

Last updated

This question evaluates parsing and processing of timestamped event logs to compute message latencies and implementation of constrained grid path search, testing competencies in file I/O, record alignment/matching, time-delta computation, graph traversal, and stateful backtracking.

You are given two coding tasks from an internship interview.

Task 1: Compute Message Latency from CSV Logs

Two systems, ComputeA and ComputeB, exchange messages. You are given two comma-separated value files:

  • ComputeA-send.csv: records when messages are sent by ComputeA.
  • ComputeB-receive.csv: records when messages are received by ComputeB.

Each file contains rows with the following columns:

  • message_type: a string identifying the message category.
  • id: a unique incrementing integer identifying the message within its type.
  • synchronized_timestamp: an integer timestamp. The clocks are synchronized across both systems.

For every message that appears in both files, print its latency, defined as:

latency = receive_timestamp - send_timestamp

Output rows should contain:

  • message_type
  • id
  • latency

Example

Send file:

message_type,id,synchronized_timestamp
altitude,0,222
altitude,2,224
altitude,1,223
altitude,3,230

Receive file:

message_type,id,synchronized_timestamp
altitude,0,223
altitude,1,225
altitude,2,226

Expected output:

message_type,id,latency
altitude,0,1
altitude,1,2
altitude,2,2

You may assume the input files can be read line by line. Clarify how your solution handles messages that appear in only one file.

Task 2: Determine Whether a String Can Be Formed in a Grid

Given an m x n grid of characters and a target string, determine whether the target string can be formed by starting at any cell and repeatedly moving one step up, down, left, or right.

Rules:

  • Each move must go to an orthogonally adjacent cell.
  • The same grid cell cannot be used more than once in a single path.
  • Return true if the target string can be formed; otherwise return false.

Example

grid = [
 ['A','B','C','E'],
 ['S','F','C','S'],
 ['A','D','E','E']
]
target = "ABCCED"

Expected output:

true