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.

HardTechnical
0 practiced
Write a Python function that returns top-k largest distinct numbers from a very large file of integers that may not fit into memory. Discuss multiple practical approaches: external sort (merge), reservoir sampling combined with selection, and streaming heap-based selection, and explain I/O and memory trade-offs for each.
EasyTechnical
0 practiced
Write two Python 3 expressions: (1) a list comprehension that generates squares of integers from 0 to n-1, and (2) a generator expression that does the same. Explain the memory and performance differences and state which approach you'd pick in a data processing pipeline when n can be very large (for example, 10 million).
MediumTechnical
0 practiced
Implement in Python a stable sort of a list of records by multiple keys where keys may be None and should be treated as smallest values. Provide code using a key function and explain how to handle None consistently for heterogeneous types without throwing errors during comparison.
MediumTechnical
0 practiced
Design a Python class StreamingMedian that supports add(num: float) and median() operations for a stream of numbers. Implement it using two heaps so that add runs in O(log n) and median in O(1). Provide code and explain why two heaps produce the median efficiently.
HardTechnical
0 practiced
Given an adjacency list representation of a directed graph in Python, implement a function to detect whether the graph has a cycle and, if DAG, produce a topological ordering. Provide code using DFS and explain time and space complexity and how you'd adapt for very large graphs stored as edge files.

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.