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
142 practiced
Provide concise pseudocode for the two-pointer sliding-window technique to find the maximum-length subarray with sum ≤ S for an array of positive integers:
left = 0curr_sum = 0max_len = 0for right in 0..n-1: curr_sum += A[right] while curr_sum > S: curr_sum -= A[left] left += 1 max_len = max(max_len, right - left + 1)
Explain why this is O(n) and how the approach changes if array elements can be negative.
EasyTechnical
77 practiced
Your team needs an in-memory FIFO queue for background tasks and an undo stack for operations in a web service. For each use-case, choose the simplest standard-library data structure(s). Justify your choice with time/space complexity for push/pop/peek, and mention concurrency considerations when there are multiple producers and consumers.
MediumTechnical
87 practiced
Design a data structure that supports insert(x), delete(x), and getRandom() each in expected O(1) time. Describe the combination of structures, how each operation works in detail (including edge cases), and discuss concurrency and failure modes if multiple threads perform operations concurrently.
EasyTechnical
145 practiced
List typical time and (auxiliary) space complexities, average and worst where applicable, for the following structures and operations: dynamic array (access/append/insert/delete), singly/doubly linked list (access/insert/delete), hash table (lookup/insert/delete), binary search tree and balanced BST (lookup/insert/delete), binary heap (insert/delete-min/build). Provide one example where worst-case differs from average-case.
HardTechnical
92 practiced
Compare red-black trees, AVL trees, and B-trees for on-disk versus in-memory database use. Discuss balancing costs, typical rotation counts on updates, cache behavior, node fanout, and why many storage engines prefer B-trees. As a manager, advise which tree variant your team should pick for a new storage engine and why.

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.