✅ Coding Interview Questions with Answers [Part-1] 💻🚀
1. What is the time and space complexity of your code?
Time complexity measures how the runtime grows with input size. Space complexity measures memory used. Always analyze both to optimize your solution.
2. What is the difference between an array and a linked list?
Arrays store elements contiguously with fast access by index. Linked lists store elements as nodes connected by pointers, allowing easy insertion/deletion but slower access.
3. How does a HashMap work internally?
It uses a hash function to convert keys into indexes in an array. Collisions are handled by chaining (linked lists) or open addressing.
4. What is recursion? Give an example.
Recursion is a function calling itself to solve smaller subproblems.
Example: Factorial(n) = n × Factorial(n-1), with base case Factorial(0) = 1.
5. Explain stack vs. queue.
Stack: Last In First Out (LIFO), like a stack of plates.
Queue: First In First Out (FIFO), like a line at a store.
6. What is a binary search and when to use it?
Binary search efficiently finds an item in a sorted array by repeatedly dividing the search interval in half. Use on sorted data for O(log n) time.
7. What is the difference between BFS and DFS?
BFS (Breadth-First Search) explores nodes level by level using a queue.
DFS (Depth-First Search) explores as far as possible along a branch using a stack or recursion.
8. What is dynamic programming?
A method to solve problems by breaking them into overlapping subproblems and storing solutions to avoid repeated work.
9. Solve Fibonacci using memoization.
Memoization stores already calculated Fibonacci numbers in a cache to reduce repeated calculations and improve performance from exponential to linear time.
10. Explain two-pointer technique with an example.
Use two pointers to traverse data structures simultaneously.
Example: Find if a sorted array has two numbers summing to a target by moving pointers from start and end inward.
💬 Double Tap ♥️ For Part-2!
Post #2688
2.65K
- ❤ 7