PUBLIC QUESTION PREVIEW
Data Structures & Algorithms interview questions
Arrays, trees, graphs, DP, sorting — the backbone of every technical interview.
Showing 12 of 60 source questions. Sample answers are study material, not employer-specific hiring guidance.
How to work through this preview
Attempt each question before reading its answer. For a concept, give a definition and a concrete example. For code, state constraints, walk through a small input, and check complexity. For design, separate requirements from assumptions and explain failure handling. Use real situations for behavioral answers.
QUESTION 1 / easy / conceptual
What is the time complexity of searching in a hash map, and when can it degrade to O(n)?
Sample answer
Hints to guide your next attempt
- Think about hash collisions
- What happens when all keys hash to the same bucket?
Source tags: hash-map / time-complexity / collisions
QUESTION 2 / easy / coding
Reverse a linked list in-place. What is the time and space complexity?
Sample answer
Hints to guide your next attempt
- You need three pointers: prev, current, next
- Update next before moving current forward
Source tags: linked-list / in-place / pointers
QUESTION 3 / easy / conceptual
Explain the difference between BFS and DFS. When would you prefer one over the other?
Sample answer
Hints to guide your next attempt
- Think about the data structure each uses
- Shortest path vs. exploring deep paths
Source tags: graph / bfs / dfs / traversal
QUESTION 4 / medium / conceptual
What is dynamic programming? Explain with the classic coin change problem.
Sample answer
Hints to guide your next attempt
- DP = optimal substructure + overlapping subproblems
- Build up from smaller amounts
Source tags: dynamic-programming / coin-change / memoization
QUESTION 5 / easy / coding
Given an array of integers, find two numbers that add up to a target sum. Optimise for O(n) time.
Sample answer
Hints to guide your next attempt
- A hash map lets you look up complements in O(1)
- For each number x, check if (target - x) exists
Source tags: array / hash-map / two-sum
QUESTION 6 / medium / conceptual
What is the difference between a min-heap and a max-heap? How is a heap used in Dijkstra's algorithm?
Sample answer
Hints to guide your next attempt
- Heap property: parent relationship with children
- Dijkstra needs the next shortest unvisited node fast
Source tags: heap / priority-queue / dijkstra / graph
QUESTION 7 / medium / coding
Detect a cycle in a linked list. Explain Floyd's tortoise and hare algorithm.
Sample answer
Hints to guide your next attempt
- Two pointers moving at different speeds
- If there is a cycle, they must eventually meet
Source tags: linked-list / two-pointers / cycle-detection / floyd's
QUESTION 8 / medium / conceptual
What is a balanced BST? Why does balance matter, and how does an AVL tree maintain it?
Sample answer
Hints to guide your next attempt
- Unbalanced BST worst case degrades to a linked list
- Balance factor = left height - right height
Source tags: bst / avl / balanced-tree / rotations
QUESTION 9 / medium / conceptual
What is the time complexity of quicksort? When does it perform worst, and how do you avoid it?
Sample answer
Hints to guide your next attempt
- Worst case happens when pivots are always the smallest or largest element
- Random pivot selection helps
Source tags: quicksort / sorting / pivot / time-complexity
QUESTION 10 / hard / coding
Given a binary tree, find the lowest common ancestor (LCA) of two nodes.
Sample answer
Hints to guide your next attempt
- Recurse: if current node is p or q, return it
- If both left and right return non-null, current node is the LCA
Source tags: binary-tree / lca / recursion
QUESTION 11 / easy / coding
Find the maximum subarray sum (Kadane's algorithm).
Sample answer
Hints to guide your next attempt
- Track current sum and global max
- Reset current sum to 0 when it goes negative
Source tags: array / dynamic-programming / kadane
QUESTION 12 / easy / coding
Rotate an array by K positions to the right in-place.
Sample answer
Hints to guide your next attempt
- Three reversal trick: reverse all, reverse first k, reverse rest
- K = K % n to handle K > n
Source tags: array / in-place / rotation
Check understanding, not recognition
- Can you explain the answer without reading it?
- Can you show when the approach fails or needs a different assumption?
- Can you connect the concept to a real project, task, or decision you have made?
- Can you distinguish a simplified interview example from a production requirement?
A LITTLE MORE CLARITY
Frequently asked questions
How many Data Structures & Algorithms questions are shown here?
This public preview shows 12 questions with the supplied answers from the app's 60-question Data Structures & Algorithms bank. Full interactive practice requires signing in.
Should I memorize the sample answers?
Use them as reference explanations, not a script or a guarantee of technical correctness for every environment. Explain your assumptions, validate code against your language and version, and discuss trade-offs. Behavioral answers should be built from your own experience.
What do hints and solution steps mean?
Hints identify ideas to consider before reading the answer. When the source question includes steps, they are shown as a separate walkthrough. Example capacities and design targets in a solution are assumptions for that exercise, not real system statistics.
BUILD YOUR NEXT OPPORTUNITY
Practice Data Structures & Algorithms actively.
Sign in to use the full topic bank and interactive practice workspace.