๐ง 1๏ธโฃ Tell me about yourself
โ Sample Answer:
"I have 4+ years as a software engineer specializing in full-stack development and algorithms. I've built scalable systems handling 1M+ daily users at a fintech startup using MERN stack and microservices. Expert in JavaScript/Python, system design, and competitive programming (LeetCode 2000+/2800). I love writing clean, testable code and optimizing for performance under scale."
๐ 2๏ธโฃ What is the difference between a stack and a queue?
โ Answer:
A stack follows LIFO (Last In, First Out) principle with operations push (add to top) and pop (remove from top). Use cases: function call stack, undo/redo features.
A queue follows FIFO (First In, First Out) with enqueue (add to rear) and dequeue (remove from front). Use cases: breadth-first search, task scheduling, printers.
Both O(1) operations with arrays/linked lists.
๐ 3๏ธโฃ What is the difference between time complexity and space complexity?
โ Answer:
Time complexity measures how runtime grows with input size n (e.g., O(nยฒ) quadratic loops).
Space complexity measures memory usage growth (e.g., O(n) array stores all elements).
Tradeoffs exist: recursion uses stack space O(n), iteration uses O(1). Always analyze both.
๐ง 4๏ธโฃ How do you find duplicates in an array?
โ Answer:
Optimal: Hash Set O(n) time/space
function findDuplicates(arr) {
const seen = new Set();
const dups = new Set();
for (let num of arr) {
if (seen.has(num)) dups.add(num);
else seen.add(num);
}
return Array.from(dups);
}
Space optimized: Sort O(n log n) then scan adjacent equals.๐ 5๏ธโฃ What is binary search and when would you use it?
โ Answer:
Binary search finds target in sorted array in O(log n) by repeatedly dividing search interval in half:
mid = (left + right) / 2
If arr[mid] == target return mid
If arr[mid] < target search right half
Else search left half
Use when: Data naturally sorted or sorting cost acceptable. Iterative version avoids recursion stack overflow.
๐ 6๏ธโฃ How do you reverse a linked list?
โ Answer:
Iterative O(n) solution flipping next pointers:
function reverseList(head) {
let prev = null, curr = head;
while (curr) {
let nextTemp = curr.next;
curr.next = prev;
prev = curr;
curr = nextTemp;
}
return prev;
}
Recursive: reverseList(curr.next).then(curr.next.prev = curr, curr.next = null).๐ 7๏ธโฃ What is recursion and why is the base case important?
โ Answer:
Recursion is a function calling itself with modified arguments until base case stops it. Without base case โ stack overflow.
Example Fibonacci:
function fib(n) {
if (n <= 1) return n; // Base case
return fib(n-1) + fib(n-2);
}
Memoization optimizes overlapping subproblems.๐ 8๏ธโฃ How do you merge two sorted arrays?
โ Answer:
Two-pointer technique O(n+m):
function mergeSorted(a1, a2) {
let i=0, j=0, result = [];
while (i < a1.length && j < a2.length) {
if (a1[i] < a2[j]) result.push(a1[i++]);
else result.push(a2[j++]);
}
return result.concat(a1.slice(i)).concat(a2.slice(j));
}
Handles unequal lengths cleanly.๐ง 9๏ธโฃ How do you detect a cycle in a linked list?
โ Answer:
Floyd's Tortoise & Hare: Slow moves 1 step, fast moves 2. If they meet โ cycle.
To find start: Reset slow to head, move both 1 step until meet.
function hasCycle(head) {
let slow = head, fast = head;
while (fast && fast.next) {
slow = slow.next;
fast = fast.next.next;
if (slow === fast) return true;
}
return false;
}
Double Tap โค๏ธ For More