← Questions

Python practicals: debug async code, find files by pattern, read nested JSON

0
NvidiaCodingLast asked Aug 2025

A coding interview question asked in Nvidia's coding round, last asked Aug 2025. It tests python, asyncio and debugging.

A set of short, practical Python tasks of the kind you meet in day-to-day tooling work. Read, debug and write small pieces of code, and talk through your choices.

Tasks

  1. Read code. You are shown a helper class that keeps pulling data from a response in chunks and writing it out. Explain what it does, when it stops, and what could go wrong (partial reads, unclosed files, memory).
  2. Debug async code. You are shown asynchronous Python that hangs or runs sequentially when it should run concurrently. Find the bug (for example a missing await, a blocking call inside a coroutine, or tasks never gathered) and fix it.
  3. Find files. Write a function that returns the path of every file under a directory whose name matches a pattern such as *.csv, and then read one of those CSV files into rows.
  4. Nested JSON. Load a JSON document nested about five levels deep and extract the requested fields, handling missing keys, lists versus objects, and unknown depth.

Interface for task 4

Unless you agree on a different interface with the interviewer, assume:

  • extract(doc: dict, path: str) -> list where path is dot-separated keys, a key may be followed by [i] (one list element) or [*] (every element); the result lists every value found, and a missing key or index gives [] instead of an exception.
doc = {"order": {"id": "o-17",
                 "customer": {"profile": {"address": {"city": "Austin"}}},
                 "items": [{"sku": "A1", "price": {"amount": 5}},
                           {"sku": "B2", "price": {"amount": 7}}]}}
extract(doc, "order.customer.profile.address.city")  ->  ["Austin"]
extract(doc, "order.items[*].sku")                   ->  ["A1", "B2"]
extract(doc, "order.items[1].price.amount")          ->  [7]
extract(doc, "order.customer.profile.phone")         ->  []

What a strong answer covers

  • Task 1: a correct reading of the loop's exit condition and resource handling, with a fix using with and bounded buffers.
  • Task 2: a clear diagnosis of why the code is not concurrent and a fix with asyncio.gather or asyncio.to_thread for blocking work.
  • Task 3: pathlib.Path.rglob or os.walk with fnmatch, and the csv module rather than splitting on commas.
  • Task 4: a recursive or iterative walk with clear handling of missing data, recursive versus iterative trade-offs, complexity linear in the visited part of the document, and validation (for example a JSON schema) when inputs are untrusted.

Follow-ups

  • Task 4: support a .. (recursive descent) segment that matches a key at any depth.
  • Task 3: the directory has ten million files; stream results instead of building a list.
  • Task 2: limit concurrency to 10 requests at a time.

Where it's asked

  • Nvidia · Coding · Last asked Aug 2025Live coding, often C++-leaning; each round usually opens with 10 to 15 minutes on your past work · Assume no AI unless the interviewer offers it

What it tests

python · asyncio · debugging · json

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding