Recursion Interview Problems
give some problems on recursion that are mostly asked on
interviews
Here are some classic recursion problems that are frequently asked in coding interviews,
especially for companies like Google, Amazon, and Microsoft:
1. Basic Recursion Problems:
Factorial of a Number
Given an integer n , return n! using recursion.
Fibonacci Sequence
Given n , return the n -th Fibonacci number using recursion.
Sum of Natural Numbers
Given n , find the sum of the first n natural numbers recursively.
Power of a Number
Implement power(x, n) to calculate x^n using recursion.
2. Recursion with Backtracking:
Permutations of a String/Array
Given a string or an array of distinct integers, return all possible permutations.
Subsets (Power Set Problem)
Given an array of distinct integers, return all possible subsets.
Combination Sum
Given an array of distinct integers and a target, find all unique combinations where the
chosen numbers sum to the target.
Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed
parentheses.
1/13
3. Divide and Conquer Recursion:
Merge Sort Algorithm
Implement merge sort to sort an array.
Quick Sort Algorithm
Implement quick sort for an array.
Search in Rotated Sorted Array
Given a rotated sorted array, search for a target using a modified binary search.
4. Dynamic Programming with Recursion (Top-Down Approach):
Climbing Stairs
You can climb 1 or 2 steps at a time. Given n , find the number of distinct ways to climb to the
top.
House Robber Problem
Given a list of non-negative integers representing the amount of money in each house, find
the maximum amount you can rob without alerting the police.
Longest Common Subsequence (LCS)
Given two strings, return the length of their longest common subsequence.
5. Classic Recursive Challenges:
Tower of Hanoi
Solve the Tower of Hanoi puzzle for n disks.
Sudoku Solver
Solve a Sudoku puzzle using recursion and backtracking.
Word Break Problem
Given a string and a dictionary of words, determine if the string can be segmented into a
space-separated sequence of one or more dictionary words.
N-Queens Problem
Place n queens on an n x n chessboard so that no two queens threaten each other.
2/13
6. Tree and Graph Recursion:
Binary Tree Traversals (Inorder, Preorder, Postorder)
Maximum Depth of Binary Tree
Lowest Common Ancestor in a Binary Tree
Serialize and Deserialize Binary Tree
Would you like to dive deeper into any of these problems or need help with solutions?
same on arrays
Here are some commonly asked array problems in coding interviews, ranging from easy to
hard, covering key concepts like two pointers, sliding window, divide and conquer,
dynamic programming, and greedy algorithms.
🚀 1. Easy Array Problems
Find the Maximum/Minimum Element in an Array
Given an array, find the largest and smallest elements.
Reverse an Array
Reverse the given array in-place without using extra space.
Remove Duplicates from a Sorted Array
Given a sorted array, remove duplicates in-place and return the new length.
Check if Array is Palindrome
Determine if the array reads the same forward and backward.
Move Zeros to the End
Move all zeros in the array to the end while maintaining the order of non-zero elements.
3/13
🧮 2. Two Pointers Approach
Two Sum (Sorted Array)
Given a sorted array and a target, find two numbers that sum up to the target.
Container With Most Water
Find two lines that together with the x-axis form a container, such that the container contains
the most water.
3Sum Problem
Find all unique triplets in the array that give the sum of zero.
Sort Colors (Dutch National Flag Problem)
Given an array with values 0, 1, and 2, sort it in-place without using any library sort function.
📊 3. Sliding Window Problems
Maximum Sum Subarray of Size K
Find the subarray of size k with the maximum sum.
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
Minimum Size Subarray Sum
Find the minimal length of a contiguous subarray of which the sum is greater than or equal to
the target.
Longest Subarray with At Most K Distinct Elements
Find the length of the longest subarray that contains at most k distinct elements.
⚡ 4. Divide and Conquer
Maximum Subarray (Kadane’s Algorithm - with divide and conquer)
Find the contiguous subarray with the largest sum.
Count Inversions in an Array
Count how many pairs of elements are out of order (can be solved with modified merge sort).
4/13
Search in Rotated Sorted Array
Given a rotated sorted array, find the index of a given target.
💡 5. Greedy Algorithms
Jump Game
Given an array of non-negative integers, where each element represents your maximum jump
length, determine if you can reach the last index.
Minimum Number of Arrows to Burst Balloons
Find the minimum number of arrows required to burst all balloons, where each balloon is
represented as an interval.
Gas Station Problem
You are given two integer arrays gas and cost . Find the starting gas station's index from
which you can complete the circuit.
🧠 6. Dynamic Programming on Arrays
House Robber
Given an array of non-negative integers, find the maximum amount of money you can rob
without robbing adjacent houses.
Longest Increasing Subsequence
Find the length of the longest increasing subsequence in an array.
Coin Change Problem
Given a list of coins and an amount, find the minimum number of coins needed to make up
that amount.
Partition Equal Subset Sum
Determine if the array can be partitioned into two subsets with equal sum.
5/13
🌟 7. Advanced Problems
Median of Two Sorted Arrays (Hard)
Given two sorted arrays, find the median of the combined sorted array in O(log(min(n, m)))
time.
Product of Array Except Self
Given an array nums , return an array answer such that answer[i] is the product of all the
elements of nums except nums[i] without using division.
Find the Duplicate Number
Given an array of n + 1 integers where each integer is between 1 and n, find the duplicate
number using Floyd's Tortoise and Hare algorithm.
Maximum Sum Rectangle in a 2D Matrix
Find the rectangle (sub-matrix) with the maximum sum in a 2D matrix.
Would you like to see solutions, explanations, or code for any of these problems in C++? 🚀
same on strings
Here are some of the most frequently asked string problems in coding interviews,
categorized by techniques like two pointers, sliding window, dynamic programming,
recursion, and more. These problems help test your skills in manipulating strings efficiently.
📄 1. Easy String Problems
Reverse a String
Reverse the given string in place without using extra space.
Check for Palindrome
Determine if the given string is a palindrome (reads the same backward).
Valid Anagram
Check if two strings are anagrams of each other (same characters in a different order).
Implement atoi() (String to Integer Conversion)
Convert a string to an integer, handling edge cases like signs, invalid characters, etc.
6/13
Count and Say
Given an integer n , generate the n -th term of the "count and say" sequence.
🔀 2. Two Pointers Approach
Longest Palindromic Substring
Find the longest substring that is a palindrome in a given string.
Valid Palindrome II
Given a string, return true if you can make it a palindrome by deleting at most one character.
Reverse Words in a String
Reverse the order of words in a given string while removing extra spaces.
String Rotation Check
Check if one string is a rotation of another (e.g., "erbottlewat" is a rotation of "waterbottle").
📊 3. Sliding Window Problems
Longest Substring Without Repeating Characters
Find the length of the longest substring without repeating characters.
Minimum Window Substring
Given two strings s and t , find the minimum window in s that contains all characters of
t.
Permutation in String
Given two strings s1 and s2 , return true if s2 contains a permutation of s1 .
Longest Repeating Character Replacement
Find the length of the longest substring that can be made with the same character after
replacing at most k characters.
📐 4. Divide and Conquer
7/13
Longest Common Prefix
Find the longest common prefix string among an array of strings.
Count of Palindromic Substrings
Count how many substrings in the given string are palindromic.
Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the
different ways to add parentheses.
🤔 5. Dynamic Programming on Strings
Longest Common Subsequence (LCS)
Given two strings, find the length of the longest subsequence present in both.
Edit Distance (Levenshtein Distance)
Find the minimum number of operations (insert, delete, replace) required to convert one
string to another.
Regular Expression Matching
Implement regular expression matching with support for '.' and '*' .
Wildcard Matching
Implement wildcard pattern matching with support for ? and * .
Palindrome Partitioning
Partition a string such that every substring is a palindrome and return the minimum number
of cuts needed.
🔄 6. Recursion and Backtracking
Generate All Parentheses Combinations
Given n pairs of parentheses, generate all combinations of well-formed parentheses.
Word Break Problem
Given a string and a dictionary of words, determine if the string can be segmented into space-
separated words.
8/13
Restore IP Addresses
Given a string containing digits, return all possible valid IP address combinations.
Letter Combinations of a Phone Number
Given a string of digits, return all possible letter combinations (like a phone keypad).
💡 7. Trie-Based Problems
Implement Trie (Prefix Tree)
Design and implement a Trie with insert() , search() , and startsWith() functions.
Word Search II
Given a 2D board and a list of words, find all words present in the board using Trie and
backtracking.
Longest Word in Dictionary
Find the longest word in a dictionary that can be built one character at a time by other words
in the dictionary.
⚡ 8. Advanced String Problems
Z Algorithm (Pattern Matching)
Efficient string matching algorithm to find occurrences of a pattern in a text.
Rabin-Karp Algorithm
Search for a pattern in a string using a rolling hash function.
Manacher’s Algorithm
Find the longest palindromic substring in linear time.
Minimum Number of Swaps to Make Strings Equal
Given two binary strings of equal length, return the minimum number of swaps required to
make the strings equal.
9/13
Would you like me to explain or code any specific problem in C++? 🚀
same on linked list
Here are some commonly asked linked list problems in coding interviews, categorized by
difficulty and key techniques like two pointers, recursion, stack, and advanced algorithms.
These problems help you master pointer manipulation, which is a critical skill for interviews.
🧩 1. Easy Linked List Problems
Reverse a Linked List
Reverse a singly linked list iteratively and recursively.
Detect Cycle in a Linked List
Check if the linked list has a cycle using Floyd’s Tortoise and Hare algorithm.
Find the Middle of the Linked List
Find the middle node of the linked list in one pass.
Merge Two Sorted Linked Lists
Merge two sorted linked lists into one sorted list.
Remove Duplicates from a Sorted Linked List
Remove duplicates from a sorted linked list in-place.
🚀 2. Two Pointers Technique
Nth Node from the End of Linked List
Find the n -th node from the end using two pointers.
Intersection of Two Linked Lists
Determine the node at which two singly linked lists intersect.
Remove Linked List Elements
Remove all elements from a linked list that have a specific value.
Palindrome Linked List
Check if the linked list is a palindrome using two pointers and reversing the second half.
10/13
Partition List
Given a linked list and a value x , partition it so that all nodes less than x come before nodes
greater than or equal to x .
🔄 3. Recursion-Based Problems
Reverse Linked List II (Reverse a Sublist)
Reverse a portion of the linked list from position m to n .
Swap Nodes in Pairs
Swap every two adjacent nodes in the linked list.
Add Two Numbers (Like 342 + 465)
Add two numbers represented by linked lists, where each node contains a single digit.
Flatten a Multilevel Doubly Linked List
Flatten a multilevel doubly linked list where nodes have child pointers.
📚 4. Stack-Based Problems
Next Greater Node in Linked List
Find the next greater value for each node in the linked list.
Remove N-th Node from End of List
Use a stack to find and remove the n -th node from the end.
Design a Stack with O(1) Min Operation Using a Linked List
Implement a stack that supports push, pop, and retrieving the minimum element in constant
time.
⚡ 5. Advanced Linked List Problems
Copy List with Random Pointer
Deep copy a linked list where each node has a random pointer in addition to the next pointer.
11/13
LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache using a doubly
linked list and a hash map.
Rotate Linked List
Rotate the linked list to the right by k places.
Reorder List
Rearrange a linked list from L0 → L1 → … → Ln-1 → Ln to L0 → Ln → L1 → Ln-1 → L2 →
Ln-2 .
🧠 6. Circular Linked List Problems
Insert into a Sorted Circular Linked List
Insert a new node into a sorted circular linked list.
Josephus Problem (Circular Linked List)
Solve the Josephus problem using a circular linked list.
🔍 7. Doubly Linked List Problems
Flatten a Multilevel Doubly Linked List
Flatten a doubly linked list where each node might have a child pointer pointing to another
doubly linked list.
Design Browser History
Implement browser history functionality using a doubly linked list.
🗂️ 8. Interview-Focused Problems
LRU Cache Design (LeetCode 146)
Reverse Nodes in k-Group (LeetCode 25)
Add Two Numbers II (LeetCode 445)
12/13
Odd Even Linked List (LeetCode 328)
Linked List Cycle II (LeetCode 142)
Would you like me to explain, code, or solve any of these problems in C++? 🚀
13/13