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
17 practiced
Write a Python implementation of Quickselect to find the k-th largest element and explain pivot selection trade-offs. Then describe how to modify your implementation to guarantee worst-case O(n) time (median-of-medians) and why that increases constant factors.
HardTechnical
16 practiced
Write a Python function smallest_k_pairs(A: List[int], B: List[int], k: int) that returns the k pairs (a,b) with smallest sums where A and B are sorted ascending. Implement with O(k log k) time using a heap and avoid generating all pairs. Provide code and explain correctness and complexity.
HardTechnical
22 practiced
Implement a stable in-place partition of a Python list according to predicate p(x) returning True/False such that all True elements come before False elements but relative order within each partition is preserved. Aim to minimize additional memory; explain trade-offs and time complexity.
HardTechnical
19 practiced
Implement an LRU cache class in Python 3 with methods get(key) and put(key, value) that run in O(1) time. Do not use functools.lru_cache or collections.OrderedDict; implement using a dict and a doubly linked list. Provide code and explain how operations maintain O(1) time complexity.
MediumTechnical
20 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.

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.