← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Amazon SWE coding round with a function timing problem that looks manageable until you realize the exclusive time calculation requires careful stack tracking. Not a brutal interview but the edge cases will get you if you're not careful.

Questions Asked (1)

Q1

Given a list of function execution logs in the format [function_name, start/end, timestamp], calculate both the inclusive time and exclusive time for a specified target function. Inclusive time is end minus start; exclusive time subtracts the time spent in direct child calls.

Algorithms & Data Structures
Author's notes

The inclusive part is easy, you just grab the start and end timestamps for the target.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a stack to track active function calls, pushing on start and popping on end. For the target function, compute inclusive time as end - start, and exclusive time by subtracting the durations of direct child calls (tracked via the stack).

Pro tip: Clarify assumptions about log validity and nesting, and discuss handling edge cases like recursive calls or multiple instances of the target function.

1. Parse and Validate Logs

Ensure logs are sorted by timestamp and properly nested. Handle any malformed entries.

2. Simulate Call Stack

Iterate through logs, using a stack to track active functions. On 'start', push; on 'end', pop and compute duration.

3. Compute Inclusive Time

For each instance of the target function, inclusive time = end_timestamp - start_timestamp. Sum if multiple instances.

4. Compute Exclusive Time

While the target is on the stack, track time spent in direct child calls (functions called directly by target). Subtract this from inclusive time.

5. Handle Edge Cases

Consider recursive calls, multiple target instances, and overlapping or invalid logs. Discuss with interviewer.

Key Points to Mention

  • Stack-based simulation for nested calls
  • Direct child calls vs. all descendants
  • Time complexity O(n) and space O(d) where d is max depth
  • Handling multiple instances of target function
  • Edge cases: recursion, invalid logs, unsorted timestamps
  • Clarifying assumptions with interviewer

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.