🚀 Coding Interview Questions with Answers (Part 11)
1️⃣0️⃣1️⃣ What is Memoization?
Answer:
Memoization is a top-down Dynamic Programming technique where the results of previously solved subproblems are stored (cached). When the same subproblem appears again, the stored result is returned instead of recomputing it.
Advantages:
• Avoids repeated calculations
• Improves performance
• Reduces time complexity
Example: Fibonacci sequence using recursion with caching.
1️⃣0️⃣2️⃣ What is Tabulation?
Answer:
Tabulation is a bottom-up Dynamic Programming approach that solves smaller subproblems first and stores their results in a table. The final solution is built iteratively without recursion.
Advantages:
• No recursion overhead
• Avoids stack overflow
• Often faster than memoization
Example: Fibonacci sequence using an array.
1️⃣0️⃣3️⃣ What is Backtracking?
Answer:
Backtracking is an algorithmic technique that builds a solution step by step and abandons a path as soon as it determines that the path cannot lead to a valid solution.
Applications:
• N-Queens Problem
• Sudoku Solver
• Maze Solving
• Permutations and Combinations
Time Complexity: Depends on the problem, often exponential.
1️⃣0️⃣4️⃣ What is Branch and Bound?
Answer:
Branch and Bound is an optimization technique used to solve combinatorial problems by systematically exploring all possible solutions while eliminating branches that cannot produce a better result.
Applications:
• Travelling Salesman Problem
• Job Scheduling
• Knapsack Problem
Benefit: Reduces unnecessary computations compared to brute force.
1️⃣0️⃣5️⃣ What is Recursion?
Answer:
Recursion is a programming technique where a function calls itself to solve smaller instances of the same problem.
Every recursive function must have:
• Base Case: Stops recursion.
• Recursive Case: Calls itself with a smaller input.
Examples:
• Factorial
• Fibonacci
• Tree Traversal
1️⃣0️⃣6️⃣ What is Tail Recursion?
Answer:
Tail recursion is a special type of recursion where the recursive call is the last operation performed by the function.
Advantages:
• More memory efficient
• Can be optimized into iteration by some compilers
• Reduces stack usage
1️⃣0️⃣7️⃣ What is the Sliding Window Technique?
Answer:
Sliding Window is an algorithmic technique used to solve problems involving arrays or strings by maintaining a window of elements and moving it across the data.
Applications:
• Maximum sum subarray
• Longest substring without repeating characters
• Minimum window substring
Benefit: Often reduces time complexity from O(n²) to O(n).
1️⃣0️⃣8️⃣ What is the Two Pointers Technique?
Answer:
The Two Pointers technique uses two indices that move through an array or string to solve problems efficiently.
Applications:
• Two Sum (sorted array)
• Remove duplicates
• Reverse an array
• Check palindrome
Benefit: Frequently reduces time complexity from O(n²) to O(n).
Post #2772
2.7K
- ❤ 6