This embedded DSA interview guide collects 248 questions on data structures and algorithms, answered at full depth for embedded software, firmware, and senior technical roles. Built from the curriculum of Mastering Data Structures and Algorithms using C and C++, with every answer extended into the firmware context: ISRs, RTOS internals, DMA, cache behaviour, stack budgets, flash versus RAM, and worst case timing.
Every question is laid out the same way.
- Say this out loud is the thirty second spoken answer for the interview room.
- The full explanation is the real understanding, in plain words.
- Worked example is code or a memory diagram you can trace by hand.
- Why it matters in firmware is the layer that separates a senior candidate.
- Mistakes people make is what actually costs people the offer.
Each part ends with a one line per concept revision sheet, intended for the day before an interview.
How to use this embedded DSA interview guide
Reading it cold. Work through in order. Parts 1 and 2 carry the memory model that later parts assume: the flash and RAM map, alignment, padding, and the difference between visibility, atomicity, and ordering. Skipping them makes later answers look like trivia.
Preparing for a specific interview. Part 4 (Stack and Queue) and Part 3 (Linked Lists) carry the highest density of embedded specific material: ring buffers, ISR to task handoff, intrusive RTOS lists, pool allocators, and stack overflow detection. Part 6 (Sorting) and Part 7 (Complexity) carry the judgement questions about worst case versus average case.
The night before. Read only the revision sheets at the end of each part. There are seven of them, roughly thirty lines each.
Five themes run through the whole guide, and they are what an embedded interviewer is really assessing.
- Worst case over average case. Heap sort over quick sort, preallocation over rehashing, sorted arrays over hash tables. Wherever a deadline exists, the bound is the requirement.
- Static over dynamic. Fixed pools over
malloc,consttables in flash over runtime construction, capacity fixed at link time so the build fails on your desk rather than the product failing in the field. - Iteration over recursion. An explicit stack whose size appears in the linker map and whose overflow returns an error, instead of a call stack that silently corrupts a neighbouring task.
- Measure rather than assume. Cache behaviour, small n constants, and stack high water marks defeat theory regularly.
- Ask about constraints before proposing a solution. Input size, memory budget, deadline, and whether the data is static. The right structure follows from those four answers.
Contents
| Part | Sections |
|---|---|
| Part 1: C Fundamentals, Pointers and Memory | C and C++ Fundamentals, Pointers and Memory |
| Part 2: Arrays and Strings | Arrays, Strings |
| Part 3: Recursion and Linked Lists | Recursion, Linked Lists |
| Part 4: Stack and Queue | Stack, Queue |
| Part 5: Trees and Binary Search Trees | Trees, Binary Search Tree |
| Part 6: Heap and Sorting | Heap, Sorting |
| Part 7: Hashing and Complexity | Hashing, Complexity |
Question index
Open the full index of all 248 questions (jump straight to any one)
C and C++ Fundamentals
- Q1. Difference between C and C++?
- Q2. Stack vs heap memory?
- Q3. What happens during a function call?
- Q4. What is memory alignment?
- Q5. Why does structure padding happen?
- Q6. Difference between struct and class in C++?
- Q7. What is pass by value and what does it cost?
- Q8. What is pass by pointer and what can the callee change?
- Q9. How does pass by reference differ from pass by pointer?
- Q10. Why use const?
- Q11. Static variable lifetime?
- Q12. Global variable lifetime?
- Q13. Automatic variables?
- Q14. Register keyword?
- Q15. Volatile keyword?
Pointers and Memory
- Q16. What is a pointer?
- Q17. Pointer arithmetic?
- Q18. Void pointer?
- Q19. Function pointer?
- Q20. Pointer to pointer?
- Q21. Wild pointer?
- Q22. Dangling pointer?
- Q23. Null pointer?
- Q24. Difference between NULL and nullptr?
- Q25. Double free problem?
- Q26. Memory leak?
- Q27. Shallow copy?
- Q28. Deep copy?
- Q29. Pointer to structure?
- Q30. Why use pointers?
- Q31. Pointer vs reference?
- Q32. Can a pointer point to a constant?
- Q33. Constant pointer?
- Q34. Pointer aliasing?
- Q35. How do you debug pointer corruption?
Arrays
- Q36. Static vs dynamic array?
- Q37. Array representation in memory?
- Q38. Row major formula?
- Q39. Column major formula?
- Q40. Time complexity of insertion in an array?
- Q41. Time complexity of deletion?
- Q42. Binary search?
- Q43. Why does binary search require a sorted array?
- Q44. Reverse an array?
- Q45. Rotate an array?
- Q46. Find the missing number?
- Q47. Duplicate detection?
- Q48. Pair sum, find two elements adding to a target?
- Q49. Merge two sorted arrays?
- Q50. Union of two sorted arrays?
- Q51. Intersection of two sorted arrays?
- Q52. Difference of two sorted arrays?
- Q53. Find max and min in one pass?
- Q54. Check whether an array is sorted?
- Q55. How do you increase the size of a dynamic array?
Strings
- Q56. How do you reverse a string in place safely?
- Q57. How do you reverse the words in a sentence in O(1) space?
- Q58. Palindrome check?
- Q59. String comparison?
- Q60. Anagram check?
- Q61. Find duplicate characters?
- Q62. Count vowels?
- Q63. Count words?
- Q64. Remove spaces?
- Q65. String validation?
- Q66. String tokenization?
- Q67. How do you implement strstr, and when is KMP worth it?
- Q68. How do you implement strcpy from scratch?
- Q69. How do you implement strlen from scratch?
- Q70. How do you implement strcmp from scratch?
- Q71. Why do C strings end with ‘\0’?
- Q72. UTF-8 vs ASCII?
- Q73. Common string bugs in interviews and in production?
Recursion
- Q74. What is recursion?
- Q75. Tail recursion?
- Q76. Head recursion?
- Q77. Tree recursion?
- Q78. Indirect recursion?
- Q79. Nested recursion?
- Q80. Fibonacci recursion?
- Q81. Memoization?
- Q82. Tower of Hanoi?
- Q83. Taylor series by recursion?
- Q84. Factorial?
- Q85. Power function?
- Q86. nCr by recursion?
- Q87. Recurrence relation?
- Q88. Space complexity of recursion?
- Q89. Stack overflow?
- Q90. Recursive linked list traversal?
- Q91. When is recursion a bad idea?
- Q92. Recursive binary search?
- Q93. How do you convert recursion to iteration?
Linked Lists
- Q94. What is a singly linked list and what does it cost per node?
- Q95. What does a doubly linked list buy you over a singly linked list?
- Q96. What is a circular linked list and how do you stop traversing it?
- Q97. Why use a sentinel node in a circular doubly linked list?
- Q98. How do you insert a node at the head of a linked list?
- Q99. How do you insert a node at the tail of a linked list?
- Q100. How do you insert a node at a given position?
- Q101. How do you delete a node from a linked list?
- Q102. How do you reverse a linked list iteratively?
- Q103. How do you reverse a linked list recursively?
- Q104. How do you find the middle node in a single pass?
- Q105. How do you detect a loop in a linked list?
- Q106. How do you find the start and length of a linked list loop?
- Q107. How do you remove duplicates from a sorted linked list?
- Q108. How do you insert into a sorted linked list?
- Q109. How do you merge two sorted linked lists?
- Q110. How do you concatenate two linked lists?
- Q111. How do you find where two linked lists intersect?
- Q112. How do you delete the nth node from the end in one pass?
- Q113. How do you reverse a linked list in groups of k?
- Q114. How do you deep copy a linked list with random pointers?
- Q115. Why choose a linked list over an array?
- Q116. Array versus linked list: how do the complexities compare?
- Q117. How much memory overhead does a linked list really cost?
- Q118. Why is a linked list slower than an array on real hardware?
- Q119. Where are circular linked lists used in firmware?
- Q120. Where does an RTOS use linked lists internally?
- Q121. How do you implement a free list and pool allocator?
- Q122. Can you build a lock free linked list on a microcontroller?
- Q123. What are the real embedded uses of linked lists?
Stack
- Q124. How do you implement a stack, and what does it cost?
- Q125. Why is an array stack the right choice in firmware?
- Q126. How do you implement a stack with a linked list?
- Q127. How do you check whether brackets are balanced?
- Q128. How does the shunting yard algorithm convert infix to postfix?
- Q129. How do you evaluate a postfix expression?
- Q130. What is stack overflow, and which meaning is being asked?
- Q131. What is stack underflow and how do you guard against it?
- Q132. Why must the function call stack be a stack?
- Q133. How do you evaluate an arbitrary expression end to end?
- Q134. How do you implement browser back and forward with stacks?
- Q135. How do you implement undo and redo?
- Q136. How do you write depth first search without recursion?
- Q137. How do you detect stack overflow on an embedded target?
- Q138. How do you monitor task stack usage in an RTOS?
Queue
- Q139. How do you implement a queue, and why is the naive version wrong?
- Q140. How does a circular queue tell full from empty?
- Q141. What is a deque and how do you implement one?
- Q142. What is a priority queue and how is it implemented?
- Q143. How do you implement a queue with a linked list?
- Q144. How do you implement a queue with an array?
- Q145. How do you build a queue from two stacks?
- Q146. Why use a circular queue instead of a linear array queue?
- Q147. How do you implement a lock free ring buffer in embedded C?
- Q148. How do you solve the producer consumer problem?
- Q149. How do you hand data from an ISR to a task?
- Q150. How do DMA descriptor chains work?
- Q151. When can a queue be made lock free?
- Q152. What does an RTOS queue give you over your own ring buffer?
- Q153. Where are queues used in embedded systems?
Trees
- Q154. What is a binary tree?
- Q155. What is a complete binary tree and why does the shape matter?
- Q156. What is a full binary tree?
- Q157. What is a strict binary tree, and how does it differ from full?
- Q158. What is a perfect binary tree?
- Q159. What is the difference between height and depth?
- Q160. What is preorder traversal and when do you use it?
- Q161. What is inorder traversal and why does it matter on a BST?
- Q162. What is postorder traversal and when do you need it?
- Q163. How do you do a level order traversal?
- Q164. Why are all three depth first traversals the same function?
- Q165. How do you traverse a tree without recursion?
- Q166. How do you rebuild a tree from its traversals?
- Q167. How do you count the nodes in a tree?
- Q168. How do you count the leaf nodes in a tree?
- Q169. How do you compute the height of a tree?
- Q170. How do you find the diameter of a binary tree?
- Q171. How do you find the lowest common ancestor?
- Q172. How do you serialize and deserialize a binary tree?
- Q173. Where are trees used in embedded systems?
Binary Search Tree
- Q174. What property defines a binary search tree?
- Q175. How do you search a binary search tree?
- Q176. How do you insert into a binary search tree?
- Q177. How do you delete a node from a binary search tree?
- Q178. How do you find the inorder successor?
- Q179. How do you find the inorder predecessor?
- Q180. How does insertion order change the shape of a BST?
- Q181. How do you validate a binary search tree correctly?
- Q182. What is the balance factor and how does AVL use it?
- Q183. What is the worst case for a BST and what triggers it?
- Q184. AVL versus plain BST versus red-black: which do you pick?
- Q185. What is a red-black tree and what do its invariants guarantee?
- Q186. What are the time complexities of BST operations?
- Q187. Where are binary search trees actually used?
- Q188. What BST mistakes cost candidates the offer?
Heap
- Q189. What is a max heap?
- Q190. What is a min heap?
- Q191. What does heapify do and what does it cost?
- Q192. How do you insert into a heap?
- Q193. How do you extract the root from a heap?
- Q194. How does heap sort work and when do you choose it?
- Q195. How does a heap implement a priority queue?
- Q196. What are the time complexities of heap operations?
- Q197. How do you build a timer scheduler on a min heap?
- Q198. Where are heaps used in embedded systems?
Sorting
- Q199. How does bubble sort work and is it ever the right choice?
- Q200. How does selection sort work and when does it win?
- Q201. Why is insertion sort fast on nearly sorted data?
- Q202. How does merge sort work and what does it cost in memory?
- Q203. How does quick sort work and what is its worst case?
- Q204. When do you choose heap sort over quick sort?
- Q205. How does counting sort beat O(n log n)?
- Q206. How does radix sort work?
- Q207. How does bucket sort work and when does it degrade?
- Q208. How does shell sort improve on insertion sort?
- Q209. Which sorts are stable?
- Q210. Which sorts are in place?
- Q211. What is the worst case for each sorting algorithm?
- Q212. What is the best case for each sorting algorithm?
- Q213. What is the average case for each sorting algorithm?
- Q214. Which sort for embedded?
- Q215. Why does merge sort need extra memory?
- Q216. How do you choose a quick sort pivot?
- Q217. What is hybrid sorting and why does introsort exist?
- Q218. What algorithms do std::sort and std::stable_sort use?
Hashing
- Q219. What is a hash table and what do you trade away for O(1)?
- Q220. What makes a good hash function?
- Q221. What is a hash collision and why is it unavoidable?
- Q222. How does separate chaining resolve collisions?
- Q223. How does linear probing work and what is clustering?
- Q224. How does quadratic probing reduce clustering?
- Q225. How does double hashing work?
- Q226. What is load factor and what should you keep it below?
- Q227. Why is rehashing dangerous in firmware?
- Q228. What are the average and worst case costs of a hash table?
- Q229. When should you use a lookup table instead of a hash table?
- Q230. Why do hash tables behave badly in cache?
- Q231. What is perfect hashing and when can you use it?
- Q232. What is a Bloom filter and what does it guarantee?
- Q233. How do you build an LRU cache with O(1) operations?
Complexity
- Q234. What does Big O actually mean?
- Q235. What does Big Omega mean?
- Q236. What does Big Theta mean?
- Q237. How do you work out the time complexity of a function?
- Q238. How do you work out space complexity?
- Q239. How is amortized complexity different from average case?
- Q240. How do you find the complexity of a recursive algorithm?
- Q241. What is best case complexity and why is it rarely useful?
- Q242. Why is worst case the only complexity that matters with a deadline?
- Q243. What does average case complexity assume?
- Q244. What are P, NP, and NP-complete?
- Q245. What are the recurring tradeoffs in system design?
- Q246. In what order should you optimize?
- Q247. How do you decide between memory and speed?
- Q248. How do you reason about complexity out loud in an interview?
The seven parts
| Part | Covers | Questions |
|---|---|---|
| Part 1 | C Fundamentals, Pointers and Memory | Q1–Q35 |
| Part 2 | Arrays and Strings | Q36–Q73 |
| Part 3 | Recursion and Linked Lists | Q74–Q123 |
| Part 4 | Stack and Queue | Q124–Q153 |
| Part 5 | Trees and Binary Search Trees | Q154–Q188 |
| Part 6 | Heap and Sorting | Q189–Q218 |
| Part 7 | Hashing and Complexity | Q219–Q248 |
Start at Part 1 if you are reading cold. Parts 1 and 2 carry the memory model the later parts assume.
Preparing for the architecture round as well? See Firmware Architecture Interview Questions: 100 Q&A.
How a firmware DSA screen differs from a general software one
Most DSA preparation material optimises for a different interview than the one you are walking into. A general software screen rewards the asymptotically best answer produced quickly. A firmware screen rewards the answer that still holds when the part has 64 kB of RAM, an interrupt fires in the middle of your loop, and the deadline is two milliseconds. Four differences account for most of the gap.
The bound matters more than the average. Quick sort’s O(n log n) average is the right answer in most rooms and the wrong one in this one, because its worst case is O(n squared) and a control loop cannot absorb that. Heap sort trades a worse constant factor for a guarantee, and where a deadline exists the guarantee is the requirement. The same reasoning rules out rehashing in a hot path, and recursion whose depth depends on input.
Memory is a fixed budget, not a resource you request. Every structure here is evaluated on what it costs per element and where that cost lives. A linked list is not simply O(1) insertion. It is one pointer of overhead per node, plus allocator metadata, scattered across the heap, defeating the prefetcher. Interviewers ask for the structure and listen for whether you volunteer the budget.
Concurrency is not an advanced topic here, it is the default. A queue in a general interview is a queue. A queue in a firmware interview is shared between an ISR and a task, which raises visibility, atomicity and ordering before you have written a line of it. A large share of Parts 3 and 4 exists for that reason alone.
Static beats dynamic almost every time. Fixed pools over malloc, const tables in flash over runtime construction, capacity fixed at link time so the build fails on your desk rather than the product failing in the field. Reaching for dynamic allocation by reflex is the clearest signal that a candidate has not shipped firmware.
What each level is assessed on
The same question is scored differently depending on the role. “Implement a queue” is a correctness question for a junior candidate and a judgement question for a staff candidate. Knowing which one you are being asked is most of the skill.
| Level | What the interviewer is listening for | Where to spend your preparation |
|---|---|---|
| Junior | Correct implementation, the right complexity, no off by one at the wrap | Parts 1, 2 and 3 |
| Mid | Picks the right structure and can say precisely why each alternative loses | Parts 3, 4 and 5 |
| Senior | Names the failure mode before being asked, and bounds the worst case unprompted | Parts 4, 6 and 7 |
| Staff | Reframes the question around constraints, then argues the tradeoff in both directions | Parts 6 and 7, plus the architecture round |
Study plans by the time you actually have
| Time available | Cover this | Skip this |
|---|---|---|
| Two days | The seven revision sheets, then Part 4 in full. Stack and queue carry the highest density of embedded specific material in the bank. | Trees beyond traversal order, and everything in Part 7 after Big Theta. |
| One week | Parts 1 and 4 in full, Part 3 from the linked list section onward, and the complexity questions in Part 7. Write the ring buffer from memory twice. | Radix, bucket and shell sort. Red-black internals beyond what the invariants guarantee. |
| Three weeks | All seven in order. Parts 1 and 2 first, because the later answers assume the memory model they establish. | Nothing. At three weeks the gaps are what get probed. |
Where candidates lose the offer
Across all 248 answers the “Mistakes people make” sections converge on the same five failures, and none of them are gaps in knowledge.
- Proposing a structure before asking about constraints. Input size, memory budget, deadline, and whether the data is fixed at build time. Those four answers determine the structure, and asking for them reads as experience rather than hesitation.
- Quoting the average case to a room with a deadline. If the system has a hard timing requirement, the average is decoration. State the bound first, then mention the average if it is favourable.
- Reaching for
malloc. On a constrained target, dynamic allocation invites fragmentation and unbounded timing. If you need it, say why, and say what happens when it fails. - Recursion with no depth bound. A recursive answer is fine when the depth is provably bounded and you say so. Otherwise convert it to an explicit stack whose size appears in the linker map.
- Shallow correctness. Validating a binary search tree against immediate children only, forgetting the wrap case in a circular queue, or losing the rest of the list by overwriting a link before saving it. These are the errors that cost offers, and every one of them is cheap to drill.
Common questions about the embedded DSA interview
Do embedded interviews ask LeetCode style questions? Some do, and the volume rises with company size. The difference is what happens after you produce a working solution. A general software interviewer moves on. An embedded interviewer asks what the stack depth is, whether it allocates, and what the worst case looks like on a part with no cache. Prepare the standard problems, then prepare the second conversation, which is the one this guide is built around.
C or C++? Answer in C unless the role has told you otherwise, and keep to a subset that would pass review: no dynamic allocation in the hot path, no recursion without a bound, explicit integer widths. If the role is C++, the useful signal is knowing which features cost nothing at runtime and which drag in an allocator or exception tables.
How much do they weigh trees and graphs? Less than a general software screen, and less than candidates expect. Traversal order, the array representation of a heap, and why a sorted array in flash often beats both are worth more than balancing rotations. Parts 5 and 6 are written with that weighting.
Is a whiteboard implementation expected? For ring buffers, yes, routinely. It is short enough to write under pressure and it exposes everything at once: the wrap arithmetic, the full versus empty distinction, and whether you understand who owns which index. If you drill one implementation before an interview, drill that one.
What if I have never written firmware? Say so, and lean on the constraint reasoning rather than pretending. Interviewers are used to strong software candidates crossing over. What they will not forgive is a confident answer that ignores memory, timing or concurrency, because that is the habit that ships bugs into hardware.
Work with us
Kalapi Infotech builds firmware for connected embedded products — architecture and BSP work, RTOS and bare-metal development, secure boot and OTA infrastructure. If you are hiring for these roles, or building a product that needs them, we would be glad to talk.