InterviewStack.io LogoInterviewStack.io

Data Structures and Complexity Questions

Comprehensive coverage of fundamental data structures, their operations, implementation trade offs, and algorithmic uses. Candidates should know arrays and strings including dynamic array amortized behavior and memory layout differences, linked lists, stacks, queues, hash tables and collision handling, sets, trees including binary search trees and balanced trees, tries, heaps as priority queues, and graph representations such as adjacency lists and adjacency matrices. Understand typical operations and costs for access, insertion, deletion, lookup, and traversal and be able to analyze asymptotic time and auxiliary space complexity using Big O notation including constant, logarithmic, linear, linearithmic, quadratic, and exponential classes as well as average case, worst case, and amortized behaviors. Be able to read code or pseudocode and derive time and space complexity, identify performance bottlenecks, and propose alternative data structures or algorithmic approaches to improve performance. Know common algorithmic patterns that interact with these structures such as traversal strategies, searching and sorting, two pointer and sliding window techniques, divide and conquer, recursion, dynamic programming, greedy methods, and priority processing, and when to combine structures for efficiency for example using a heap with a hash map for index tracking. Implementation focused skills include writing or partially implementing core operations, discussing language specific considerations such as contiguous versus non contiguous memory and pointer or manual memory management when applicable, and explaining space time trade offs and cache or memory behavior. Interview expectations vary by level from selecting and implementing appropriate structures for routine problems at junior levels to optimizing naive solutions, designing custom structures for constraints, and reasoning about amortized, average case, and concurrency implications at senior levels.

EasyTechnical
0 practiced
Prove, using an amortized analysis, that appending N times to a dynamic array that doubles its capacity has amortized O(1) cost per append. Describe the aggregate method and the potential (banker's) method briefly. Explain how a different growth factor (e.g., 1.5x) or a shrink-to-fit policy changes copy costs and memory usage. Provide a short numeric example: start capacity 1 and append N elements.
MediumTechnical
0 practiced
Design a data structure that supports insert(val), remove(val), and getRandom() in average O(1) time. Implement the idea in Python or pseudocode and explain complexity. How would you handle duplicates if allowed? How to modify for weighted random sampling (getRandom weighted by frequency)?
HardTechnical
0 practiced
The naive recursive algorithm for edit distance (Levenshtein) has exponential time due to repeated subproblems. Derive its complexity, then present the classic dynamic programming O(n*m) solution, explain memory reduction to O(min(n,m)) using rolling arrays, and detail banded DP to reduce complexity to O(k * min(n,m)) when the edit distance is guaranteed to be ≤ k. Discuss practical heuristics for long sequences in bioinformatics or token alignment in NLP.
MediumTechnical
0 practiced
Implement an LRUCache class in Python with methods get(key) and put(key, value). Both operations should be O(1) average time. The cache has a fixed capacity and evicts the least-recently-used item when full. Provide a brief explanation of your chosen data structures and analyze time/space complexity. (You may use Python, pseudocode, or standard library primitives.)
EasyTechnical
0 practiced
Compare hash table collision resolution strategies: separate chaining, linear probing, quadratic probing, and double hashing. For each, discuss average and worst-case costs for lookup/insert/delete, memory overhead, cache performance, and practical tuning knobs (load factor, resizing). For an AI Engineer maintaining large vocab caches or embedding lookups, recommend scenarios where open addressing or chaining is preferable.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.