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
19 practiced
Implement a sliding_window_median(nums: List[int], k: int) -> List[float] in Python that returns the median for each sliding window of size k over nums. The solution must handle deletions when elements slide out efficiently (use two heaps with delayed-deletion) and achieve O(n log n) overall time. Provide code and explain handling of duplicates.
EasyTechnical
16 practiced
Describe the differences between list.sort() and the built-in sorted() function in Python. Explain the role and performance cost of the key function and the fact that Timsort is stable. Give a concrete example: sort a list of (score, id) tuples by score descending then id ascending, showing both approaches.
EasyTechnical
18 practiced
Compare the average and worst-case time and space complexities of Python's built-in data structures (list, tuple, dict, set) for common operations: indexing, append/appendleft, pop, insert, delete, membership test, and iteration. Give concrete examples of when, in an AI data-processing pipeline (e.g., feature lookup, batched sampling, streaming logs), you would prefer one structure over another and why.
HardTechnical
21 practiced
You must compute pairwise cosine similarities between 100,000 sparse vectors where each vector has on average 100 non-zero entries. Propose an end-to-end Python implementation plan to minimize compute and memory: data representation, inverted index to find candidate pairs, blocking/sharding strategy, use of scipy.sparse or C-extensions, and estimate operations and memory. Describe how you'd parallelize across machines or cores and reduce IO.
HardTechnical
21 practiced
Design and implement (or provide detailed pseudocode with Python I/O patterns) an external sort utility to sort a file that is larger than RAM. Explain chunking strategy, in-memory sort for chunks, writing temporary files, and a k-way merge using heapq.merge. Discuss choices for chunk size, temp file management, and I/O buffering to minimize disk seeks.

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.