Challenge - 5 Problems
Stack Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediateMemory Usage Comparison
Which statement best describes the memory usage difference between a stack implemented using a linked list and one implemented using an array?
Attempts:
2 left
💡 Hint
Think about how linked lists store elements compared to arrays.
✗ Incorrect
A linked list stack stores each element in a node that contains the data and a pointer to the next node, which uses extra memory. An array stack stores elements in contiguous memory without pointers.
🧠 Conceptual
intermediateStack Size Flexibility
Which stack implementation allows dynamic resizing without a fixed maximum size?
Attempts:
2 left
💡 Hint
Consider which structure can grow without predefined limits.
✗ Incorrect
Linked list stacks can grow dynamically by adding nodes, while fixed size arrays have a maximum capacity.
❓ Predict Output
advancedPush Operation Time Complexity
What is the output of the following TypeScript code simulating push operations on both stack types?
DSA Typescript
class ArrayStack { private stack: number[] = []; push(item: number) { this.stack.push(item); } size() { return this.stack.length; } } class LinkedListNode { constructor(public value: number, public next: LinkedListNode | null = null) {} } class LinkedListStack { private head: LinkedListNode | null = null; private count = 0; push(item: number) { const node = new LinkedListNode(item, this.head); this.head = node; this.count++; } size() { return this.count; } } const arrayStack = new ArrayStack(); const linkedListStack = new LinkedListStack(); arrayStack.push(10); arrayStack.push(20); linkedListStack.push(10); linkedListStack.push(20); console.log(arrayStack.size()); console.log(linkedListStack.size());
Attempts:
2 left
💡 Hint
Count how many push operations were done on each stack.
✗ Incorrect
Both stacks have two push operations, so their sizes are both 2.
❓ Predict Output
advancedPop Operation Behavior
What will be the output after popping one element from each stack below?
DSA Typescript
class ArrayStack { private stack: number[] = []; push(item: number) { this.stack.push(item); } pop() { return this.stack.pop(); } } class LinkedListNode { constructor(public value: number, public next: LinkedListNode | null = null) {} } class LinkedListStack { private head: LinkedListNode | null = null; push(item: number) { const node = new LinkedListNode(item, this.head); this.head = node; } pop() { if (!this.head) return null; const val = this.head.value; this.head = this.head.next; return val; } } const arrayStack = new ArrayStack(); const linkedListStack = new LinkedListStack(); arrayStack.push(5); arrayStack.push(15); linkedListStack.push(5); linkedListStack.push(15); console.log(arrayStack.pop()); console.log(linkedListStack.pop());
Attempts:
2 left
💡 Hint
Stacks remove the last pushed item first.
✗ Incorrect
Both stacks remove the last pushed element, which is 15.
🧠 Conceptual
expertPerformance Trade-offs in Large Scale
In a system where millions of push and pop operations occur frequently, which stack implementation trade-off is most significant?
Attempts:
2 left
💡 Hint
Think about resizing costs and memory overhead.
✗ Incorrect
Array stacks may need to resize and copy elements, which is costly, while linked list stacks avoid resizing but use extra memory for pointers.
