InterviewStack.io LogoInterviewStack.io

Python Coding and Data Structures Questions

Proficiency in Python, including arrays, dictionaries, linked lists, and basic algorithms. Ability to write efficient, clean code under time pressure. Understanding of time/space complexity and optimization.

HardTechnical
25 practiced
Design and implement a memory-efficient algorithm in Python to compute the top-k most frequent n-grams from a corpus stored on disk that is much larger than available RAM. Describe streaming extraction, approximate counting methods (Count-Min Sketch, lossy counting), and how to merge partial results when processing shards in parallel.
HardTechnical
26 practiced
Implement in Python a memory- and compute-efficient function to compute pairwise Euclidean distances between N high-dimensional points where N is large but each point fits in memory. Your function should support chunked processing, optional multiprocessing, and use symmetric property to reduce work. Provide code and discuss numerical stability and precision choices (float32 vs float64).
MediumTechnical
30 practiced
Implement a memory-efficient function pairwise_cosine_similarity(A, B, batch_size=1024) in Python using NumPy that computes cosine similarity between two collections of vectors A (m x d) and B (n x d). Both m and n may be large, so your function should process data in chunks to avoid O(m*n) memory. Show code and explain numerical stability and complexity.
HardSystem Design
24 practiced
Design a compact file format to store multiple large NumPy arrays and associated metadata in a single file with random access. In Python, sketch a serializer and deserializer that writes a header with offsets, allows memory-mapping of each array on demand (numpy.memmap), supports versioning, and optionally supports per-array compression. Focus on format outline and the key implementation steps.
MediumTechnical
26 practiced
Implement an LRUCache class in Python with O(1) get(key) and put(key, value) without using functools.lru_cache. The cache should have a capacity limit and evict the least recently used item when full. Optionally discuss thread-safety considerations if used in a model-serving process.

Unlock Full Question Bank

Get access to hundreds of Python Coding and Data Structures interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.