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
20 practiced
Explain how Python's sort (Timsort) achieves stability and good performance on partially ordered data. Give examples of when stability is required in multi-key sorting in a data-science workflow and demonstrate with Python code how to sort by multiple keys preserving stability.
MediumTechnical
16 practiced
Given a sorted list of unique timestamps and a window length w seconds, implement in Python an efficient function that returns the maximum number of events in any sliding window of length w. Aim for O(n) time using a two-pointer approach or deque and explain the complexity.
MediumTechnical
16 practiced
Write Python code to merge overlapping intervals given as a list of [start, end] pairs. Your solution should run in O(n log n) time and handle edge cases like touching intervals, single-point intervals, and invalid ranges. Explain correctness.
EasyTechnical
19 practiced
You have a list of strings representing event types. Using collections.Counter in Python 3, write code to produce the top 5 most common events and explain its time complexity. When is Counter.most_common more convenient than manual heap approaches for top-k frequency extraction?
HardTechnical
24 practiced
Given a Python list of potentially millions of small lists (e.g., feature vectors), design a memory-efficient representation and access pattern in pure Python (no pandas/numpy) to reduce overhead. Discuss the trade-offs between storing as list-of-lists, flat list with offsets, and using array.array or memoryview structures.

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.