Parse API JSON and print org chart
Task 1: Call an HTTP API and Parse JSON
You are provided with an HTTP endpoint that returns JSON data describing transit stops.
API Response Format
The response body is is guaranteed to be valid JSON, structured as follows:
{
"stops": [
{"id": "123", "name": "South Station", "description": "Commuter rail hub"},
{"id": "456", "name": "Park Street", "description": "Red/Green lines"}
]
}
Requirements
- Make a GET request to the specified endpoint.
- Parse the JSON response. For each stop, extract its
nameanddescription. Note that thedescriptionfield may be missing or empty. - Print one line per stop in the format:
<name> - <description>.
Follow-up Discussion
Discuss what changes would be necessary to transform this into production-quality code, considering aspects such as error handling, retries/timeouts, logging/metrics, handling schema changes, pagination, and testing.
Task 2: Build an Org Chart from CSV
You are given a CSV file where each row represents an employee and contains the following fields: employee_name,title,department,manager_name.
Input Details
- The
manager_namefield will be empty for the top-level leader. - Each employee has at most one manager.
Goal
Print the organization structure such that each manager appears before their direct reports.
Output Format
- Print one employee per line.
- Use 2 spaces of indentation per level:
- Level 0: top-level leader
- Level 1: direct reports
- Level 2: reports of level-1 employees
- And so on.
Ordering
For each manager, their direct reports must be printed in lexicographic order by employee_name.
Example
Given the following input rows (order in file is arbitrary):
Alice,CEO,Executive,
Bob,CFO,Finance,Alice
Carol,Analyst,Finance,Bob
Dave,Intern,Finance,Carol
Eve,COO,Operations,Alice
Frank,CTO,Engineering,Alice
The expected output is:
Alice
Bob
Carol
Dave
Eve
Frank
Constraints and Assumptions
- The input data contains no cycles (i.e., no employee reports to themselves directly or indirectly in a loop).
- Every non-empty
manager_namerefers to an employee whose record is present in the file. - The CSV file can be large enough that an O(N^2) approach for building the structure may time out. Aim for a solution with near O(N log N) or better time complexity (excluding the time complexity for sorting within report lists).
AI interview prep
Core dilemma
Balancing efficient data structure construction and traversal for hierarchical data (Task 2) with robust, production-grade handling of external dependencies and data variability (Task 1 follow-up). Task 1 serves as a warm-up, while Task 2 is the primary algorithmic challenge.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Parse API JSON and print org chart
Task 1: Call an HTTP API and Parse JSON
You are provided with an HTTP endpoint that returns JSON data describing transit stops.
API Response Format
The response body is is guaranteed to be valid JSON, structured as follows:
{
"stops": [
{"id": "123", "name": "South Station", "description": "Commuter rail hub"},
{"id": "456", "name": "Park Street", "description": "Red/Green lines"}
]
}
Requirements
- Make a GET request to the specified endpoint.
- Parse the JSON response. For each stop, extract its
nameanddescription. Note that thedescriptionfield may be missing or empty. - Print one line per stop in the format:
<name> - <description>.
Follow-up Discussion
Discuss what changes would be necessary to transform this into production-quality code, considering aspects such as error handling, retries/timeouts, logging/metrics, handling schema changes, pagination, and testing.
Task 2: Build an Org Chart from CSV
You are given a CSV file where each row represents an employee and contains the following fields: employee_name,title,department,manager_name.
Input Details
- The
manager_namefield will be empty for the top-level leader. - Each employee has at most one manager.
Goal
Print the organization structure such that each manager appears before their direct reports.
Output Format
- Print one employee per line.
- Use 2 spaces of indentation per level:
- Level 0: top-level leader
- Level 1: direct reports
- Level 2: reports of level-1 employees
- And so on.
Ordering
For each manager, their direct reports must be printed in lexicographic order by employee_name.
Example
Given the following input rows (order in file is arbitrary):
Alice,CEO,Executive,
Bob,CFO,Finance,Alice
Carol,Analyst,Finance,Bob
Dave,Intern,Finance,Carol
Eve,COO,Operations,Alice
Frank,CTO,Engineering,Alice
The expected output is:
Alice
Bob
Carol
Dave
Eve
Frank
Constraints and Assumptions
- The input data contains no cycles (i.e., no employee reports to themselves directly or indirectly in a loop).
- Every non-empty
manager_namerefers to an employee whose record is present in the file. - The CSV file can be large enough that an O(N^2) approach for building the structure may time out. Aim for a solution with near O(N log N) or better time complexity (excluding the time complexity for sorting within report lists).