cswork / libraryOpen practice workspace

Interview questions · Cortex

Parse API JSON and print org chart

This question evaluates HTTP and JSON parsing, CSV processing, hierarchical data modeling, sorting, and algorithmic efficiency for building and printing an organizational chart.

You will solve two practical coding tasks.

Task 1: Call an HTTP API and parse JSON

You are given an HTTP endpoint that returns JSON describing transit stops.

API response format

Assume the response body is valid JSON shaped like:

{
  "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 endpoint.
  • Parse the JSON and extract, for each stop:
    • name
    • description (may be missing or empty)
  • Print one line per stop in the format:
<name> - <description>

Follow-ups (discussion)

  • What changes would you make to turn this into production-quality code (error handling, retries/timeouts, logging/metrics, schema changes, pagination, testing, etc.)?

Task 2: Build an org chart from CSV

You are given a CSV file where each row contains:

employee_name,title,department,manager_name
  • manager_name is empty for the top-level leader.
  • Each employee has at most one manager.

Goal

Print the organization structure so that each manager appears before their reports.

Output format

Print one employee per line with 2 spaces of indentation per level:

  • Level 0: top-level leader
  • Level 1: direct reports
  • Level 2: reports of level-1 employees
  • etc.

Ordering

For each manager, print their direct reports in lexicographic order by employee_name.

Example

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

Expected output:

Alice
  Bob
    Carol
      Dave
  Eve
  Frank

Constraints / assumptions

  • The input contains no cycles.
  • Every non-empty manager_name refers to an employee present in the file.
  • The file can be large enough that an O(n^2) approach may time out; aim for near O(n log n) or better (excluding sorting within report lists).

Community answers

Nothing here yet.

Join in on CSWork →