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
Implement a feature-hashing (hashing-trick) transformer in Python that maps high-cardinality categorical values to a fixed number of bins, supports signed hashing to reduce bias, and returns a sparse count representation per instance (e.g., dict or scipy.sparse). Include a streaming API and discuss how to choose the number of bins and measure collision impact.
EasyTechnical
0 practiced
Given a Python list of labels (strings) representing predicted classes (for example: ['cat','dog','cat','bird',...]), write code using collections.Counter to return the top 5 most frequent labels and their counts. Explain briefly how Counter.most_common works internally and the approximate time/space complexity for large inputs.
MediumTechnical
0 practiced
Show how to safely update a shared Python dict of counters from multiple threads. Provide an example using threading.Lock or collections.Counter with explicit locking, explain which operations are atomic due to the GIL and which are not, and discuss when to choose multiprocessing or an external store for parallelism in ML pipelines.
MediumTechnical
0 practiced
Explain what makes an object hashable in Python and why hashability matters when using sets or dicts for feature aggregation. Discuss pitfalls when using mutable objects as keys, how __hash__ and __eq__ interact, and the implications of using floats (including NaN) as dict keys in ML pipelines.
HardTechnical
0 practiced
You run a Python feature-extraction pipeline on millions of images where each image produces a dictionary of features. Memory spikes occur during batch processing. Describe a practical process to profile memory usage, identify heavy objects (PIL images, numpy arrays, per-image dicts), and reduce memory pressure (generators, streaming, memmap, object pooling). List concrete tools you would use and step-by-step actions.

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.