InterviewStack.io LogoInterviewStack.io

Python Data Structures and Algorithms Questions

Core Python data structure and algorithm knowledge used for manipulating collections and solving common data processing problems. Candidates should know built in types such as lists, dictionaries, sets, and tuples and their performance characteristics; be able to implement and reason about searching, sorting, counting, deduplication, and frequency analysis tasks; and choose appropriate algorithms and data structures for time and space efficiency. Familiarity with Python standard library utilities such as collections.Counter, defaultdict, deque, and heapq is expected, as is writing Pythonic, clear code that handles edge cases. Questions may include algorithmic trade offs, complexity analysis, and applying these techniques to practical data manipulation problems where custom logic is required beyond what pandas or NumPy provide.

MediumTechnical
0 practiced
Implement merge_k_sorted_files(file_paths: List[str]) -> Iterator[int] in Python that merges multiple sorted files of integers into a single sorted stream of integers. Ensure minimal memory usage, proper closing of file handles, and discuss how to deal with a very large number of files (file descriptor limits).
MediumTechnical
0 practiced
Write a Python generator rle_encode(stream: Iterator[Any]) -> Iterator[Tuple[Any, int]] that yields (value, count) pairs for consecutive identical values in the input stream (run-length encoding). The implementation must be streaming (O(1) memory) and handle empty streams correctly. Explain use-cases where RLE provides benefits in log compression.
HardTechnical
0 practiced
Design a multi-threaded/process pipeline in Python that reads CSV files, applies transformations, and writes partitioned Parquet files concurrently. Explain architecture choices to handle backpressure (bounded queues), graceful shutdown, retries on transient IO errors, and ensuring no data loss (atomic writes). Mention relevant libraries (pyarrow, fastparquet) and how you'd test fault tolerance.
MediumTechnical
0 practiced
Given k sorted iterators (they may be file streams), implement merge_sorted(iterables: List[Iterator[int]]) -> Iterator[int] in Python that merges them into one sorted iterator with minimal memory. Use heapq.merge or implement a k-way merge yourself. Discuss how to handle a very large k (file descriptor limits) and I/O bottlenecks.
MediumTechnical
0 practiced
Using the bisect module, implement insert_timestamp(sorted_list: List[int], timestamp: int) that inserts a timestamp while maintaining sorted order. Discuss the amortized cost for many insertions into a large list and evaluate alternative data structures (balanced BST, skip list, sortedcontainers) for workloads with frequent inserts.

Unlock Full Question Bank

Get access to hundreds of Python Data Structures and Algorithms interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.