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 an LFUCache class in Python that supports get(key) and put(key, value) with capacity eviction policy: when capacity is reached evict the least-frequently used key; if multiple keys share the same frequency evict the least-recently-used among them. Both get and put must run in O(1) amortized time. Provide code and explanation.
EasyTechnical
0 practiced
Describe requirements for objects to be valid Python dict keys. Explain how __hash__ and __eq__ interact, and show common pitfalls when using mutable or custom objects as keys in data processing pipelines. Outline how you would make a custom class safely hashable for use as a dict key.
HardTechnical
0 practiced
Given a stream of integers too large to fit in memory, design a Python approach to find all unique pairs that sum to a target value. Describe sharding/hash-partitioning on disk, external sorting approaches, and give code sketches for the in-memory phase that processes a shard. Discuss handling duplicates, negative numbers, and memory limits.
MediumTechnical
0 practiced
Explain the Python Global Interpreter Lock (GIL) and its practical implications for CPU-bound and I/O-bound data processing in AI pipelines. Compare approaches: multithreading, multiprocessing, asyncio, and using native extensions (NumPy/Cython), and recommend when each is appropriate for parallelism in Python.
HardTechnical
0 practiced
Discuss hash-collision and hash-flooding attacks on Python dicts when processing untrusted input. Explain Python's hash randomization, its limits, and practical mitigation strategies (for example, limiting per-request dict sizes, using specialized parsers, or switching to alternative data structures). How would you detect and respond to such attacks in production AI services?

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.