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 a trustworthy flatten_dict(d: dict) function in Python that converts nested dictionaries into a single-level dict with dot-separated keys (e.g., {'a':{'b':1}} -> {'a.b':1}). The implementation must handle non-dict values, lists as values, and avoid name collisions. Provide code and discuss edge cases such as keys containing dots.
HardSystem Design
0 practiced
Given two extremely large sorted arrays A and B on disk (cannot fit both arrays into memory), design a Python-friendly algorithm to find the k smallest pairs (a,b) by sum. Describe I/O-efficient approaches using iterators, min-heaps on partial windows, and how to minimize disk reads and memory footprint.
HardTechnical
0 practiced
Implement a Python function group_anomalies_by_frequency(items: Iterable[str], threshold: int) that returns keys whose frequency exceeds threshold, using only O(m) memory where m is number of unique candidates above threshold, assuming most items are low-frequency. Hint: use the Misra-Gries algorithm (space-saving). Provide code and explain correctness.
MediumTechnical
0 practiced
Write a Python generator chunks(iterable, size) that yields lists of length 'size' from an arbitrary iterable. The function should work for iterators that do not support len() and should not load the entire iterable into memory. Provide code and discuss edge cases like size <= 0 or empty iterables.
MediumTechnical
0 practiced
Implement an efficient algorithm in Python to group anagrams from a list of strings and return groups as lists. Compare two approaches: sorting each string as a key and using a 26-length frequency tuple as a key. Discuss time/space trade-offs for very long strings and for a very large number of short strings.

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.