Hot Topics
Top Advanced Coding for Interview Preparation
Coding Questions on Divided and Conquer
Binary Search: Implement the binary search algorithm to find a target element in a sorted array.
Merge Sort: Implement the merge sort algorithm to sort an array of integers.
Quick Sort: Implement the quicksort algorithm to sort an array of integers.
Count Inversions: Given an array, count the number of inversions, i.e., the number of pairs (i, j) where i < j and arr[i] > arr[j].
Closest Pair of Points: Given an array of points in a 2D plane, find the two points with the smallest Euclidean distance between them.
Maximum Subarray Sum: Given an array of integers, find the contiguous subarray with the largest sum.
Matrix Multiplication: Implement a divide and conquer algorithm to multiply two matrices efficiently.
Maximum Product Subarray: Given an array of integers, find the contiguous subarray with the largest product.
Counting Inversions in an Array: Implement a divide and conquer algorithm to count the number of inversions in an array.
Kth Largest Element in an Array: Find the kth largest element in an unsorted array using a divide and conquer approach.
Median of Two Sorted Arrays: Find the median of two sorted arrays using the divide and conquer technique.
Longest Common Subsequence: Find the longest common subsequence between two strings using the divide and conquer approach.
Maximum Subarray Sum Circular: Find the maximum sum of a circular subarray in an array using the divide and conquer approach.
Majority Element: Find the majority element (appearing more than n/2 times) in an array using the divide and conquer technique.
Maximum Area of Histogram: Given an array representing the heights of bars in a histogram, find the largest rectangular area using the divide and conquer technique.
Search in Rotated Sorted Array: Search for a target element in a rotated sorted array using the divide and conquer approach.
Reverse Bits: Reverse the bits of a 32-bit unsigned integer using the divide and conquer technique.
Number of Inversions in a Sequence: Given a sequence of numbers, find the number of inversions using the divide and conquer approach.
Longest Increasing Subsequence: Find the length of the longest increasing subsequence in an array using the divide and conquer technique.
Count Complete Tree Nodes: Count the number of nodes in a complete binary tree using the divide and conquer approach.
Find Minimum in Rotated Sorted Array: Find the minimum element in a rotated sorted array using the divide and conquer technique.
K Closest Points to Origin: Given an array of points in a 2D plane, find the k closest points to the origin using the divide and conquer approach.
Smallest Common Region: Given a list of regions and their parent-child relationships, find the smallest common region using the divide and conquer technique.
Maximum Depth of Binary Tree: Find the maximum depth of a binary tree using the divide and conquer approach.
Range Sum Query – Immutable: Given an array of integers, find the sum of elements in a given range using the divide and conquer technique.
Convert Sorted Array to Binary Search Tree: Convert a sorted array into a height-balanced binary search tree using the divide and conquer approach.
Unique Binary Search Trees: Given n, generate all unique binary search trees that store values from 1 to n using the divide and conquer technique.
Largest Rectangle in Histogram: Find the largest rectangle area in a histogram using the divide and conquer approach.
Inorder Successor in BST: Find the inorder successor of a given node in a binary search tree using the divide and conquer technique.
Maximum Difference Between Node and Ancestor: Find the maximum difference between a node and its ancestor in a binary tree using the divide and conquer approach.
Count of Smaller Numbers After Self: Given an array, count the number of smaller elements to the right of each element using the divide and conquer technique.
Subarray Sum Equals K: Given an array, find the total number of continuous subarrays whose sum equals a target value using the divide and conquer approach.
Maximum Average Subarray: Given an array, find the maximum average of any contiguous subarray of length k using the divide and conquer technique.
Validate Binary Search Tree: Validate whether a binary tree is a binary search tree using the divide and conquer approach.
Largest BST Subtree: Find the largest subtree that is a binary search tree in a binary tree using the divide and conquer technique.
Construct Binary Tree from Inorder and Postorder Traversal: Given inorder and postorder traversal arrays, construct the corresponding binary tree using the divide and conquer approach.
Find First and Last Position of Element in Sorted Array: Given a sorted array, find the first and last position of a target element using the divide and conquer technique.
Count Complete Tree Nodes: Count the number of nodes in a complete binary tree using the divide and conquer approach.
Search for a Range: Given a sorted array, find the starting and ending position of a target element using the divide and conquer technique.
Pow(x, n): Implement the pow(x, n) function using the divide and conquer approach.
Search in 2D Matrix: Given a 2D matrix sorted row-wise and column-wise, search for a target element using the divide and conquer technique.
Construct Binary Tree from Preorder and Inorder Traversal: Given preorder and inorder traversal arrays, construct the corresponding binary tree using the divide and conquer approach.
Product of Array Except Self: Given an array, calculate the product of every element except itself using the divide and conquer technique.
Count Complete Tree Nodes: Count the number of nodes in a complete binary tree using the divide and conquer approach.
Count of Range Sum: Given an array, count the number of subarrays whose sum falls within a given range using the divide and conquer technique.
Validate Binary Search Tree: Validate whether a binary tree is a binary search tree using the divide and conquer approach.
Longest Substring Without Repeating Characters: Find the length of the longest substring without repeating characters using the divide and conquer technique.
Search a 2D Matrix II: Given a 2D matrix sorted row-wise and column-wise, search for a target element using the divide and conquer technique.
Majority Element II: Given an array, find all elements that appear more than ⌊ n/3 ⌋ times using the divide and conquer approach.
Word Search II: Given a 2D board of letters and a list of words, find all words that can be formed by sequentially following adjacent cells using the divide and conquer technique.
Coding Questions on Greedy algorithm
Minimum Spanning Tree (MST):
Kruskal’s Algorithm
Prim’s Algorithm
Dijkstra’s Shortest Path Algorithm:
Single Source Shortest Path
All Pairs Shortest Path
Huffman Coding:
Encoding and Decoding
Interval Scheduling:
Maximum Subset of Non-overlapping Intervals
Coin Change Problem:
Minimum Number of Coins Required
Job Sequencing:
Maximum Profit Job Scheduling
Scheduling to Minimize Lateness
Activity Selection Problem:
Maximum Number of Non-overlapping Activities
Fractional Knapsack Problem:
Maximum Value Subset
Gas Station Problem:
Circular Tour
Minimum Number of Platforms:
Arrival and Departure at Railway Station
Water Connection Problem:
Minimum Cost to Supply Water to All Houses
Buy Maximum Stocks:
Stock Buy-Sell to Maximize Profit
Minimum Cost Spanning Tree:
Find the MST with Minimum Cost
Connect Ropes to Minimize Cost:
Minimum Cost to Connect Ropes
Job Sequencing with Deadlines:
Maximum Profit with Job Deadlines
Task Scheduling Problem:
Minimum Time Interval for Tasks
Activity Notifications:
Minimum Number of Notifications
Jump Game:
Minimum Number of Jumps
Maximum Activities:
Maximum Activities to be Performed
Maximum Guest at a Party:
Maximum Number of Guests in a Party
Minimum Time Difference:
Minimum Difference Between Time Points
Minimum Swaps for Bracket Balancing:
Minimum Number of Swaps for Balanced Brackets
Minimum Product Subset of an Array:
Minimum Product Subarray
Largest Permutation:
Find the Largest Permutation Possible
Maximum Length of Pair Chain:
Longest Chain of Pairs
Minimum Cost to Cut a Board:
Minimum Cost to Cut a Board into Squares
Activity Selection Problem with Multiple Time Intervals:
Maximum Number of Non-overlapping Activities with Multiple Time Intervals
Minimum Cost of Ropes:
Minimum Cost to Connect Ropes of Different Lengths
Minimize Cash Flow:
Minimum Transactions to Settle Cash Flow
Buy Maximum Toys:
Maximum Number of Toys with a Given Budget
Maximum Product Subset of an Array:
Maximum Product Subarray
Maximum Length of Subarray with Positive Product:
Longest Subarray with Positive Product
Minimum Add to Make Parentheses Valid:
Minimum Number of Additions to Balance Parentheses
Minimum Swap Required to Group All 1s Together:
Minimum Number of Swaps to Group All 1s Together
Reorganize String:
Rearrange String to Have No Adjacent Repeating Characters
Minimum Number of Platforms Required for a Railway Station:
Minimum Platforms to Accommodate All Trains
Meeting Rooms II:
Minimum Number of Meeting Rooms Required
Buy Maximum Advertising Slots:
Maximum Revenue from Ad Slots
Maximum Number of Distinct Elements After Removing K Elements:
Maximum Number of Distinct Elements after Removing K Elements
Maximum Sum Increasing Subsequence:
Maximum Sum Increasing Subsequence
Minimum Number of Train Platforms Required for a Station:
Minimum Platforms to Accommodate All Trains
Longest Subsequence with Consecutive Elements:
Longest Subsequence with Consecutive Elements
Maximum Sum Path in Two Arrays:
Maximum Sum Path in Two Arrays
Maximum Number of Assignments:
Maximum Number of Assignments with Given Constraints
Maximum Average Sum Partition:
Maximum Average Sum Partition
Largest Sum Subarray with at Least K Numbers:
Largest Sum Subarray with at Least K Numbers
Minimum Steps to Make Product Equal One:
Minimum Steps to Make Product Equal One
Maximize Product of Subarray with Given Size:
Maximize Product of Subarray with Given Size
Minimum Cost for Tickets:
Minimum Cost for Tickets
Maximum Number of Balloons:
Maximum Number of Balloons
Coding Questions on dynamic programming
Fibonacci Series: Find the nth number in the Fibonacci series using dynamic programming.
Longest Common Subsequence: Find the longest common subsequence between two strings using dynamic programming.
0/1 Knapsack Problem: Given a set of items with weights and values, determine the maximum value that can be obtained by selecting items without exceeding a given weight limit.
Longest Increasing Subsequence: Find the length of the longest increasing subsequence in an array using dynamic programming.
Edit Distance: Find the minimum number of operations required to transform one string into another, where the operations can be insertion, deletion, or substitution of a character.
Maximum Subarray Sum: Find the contiguous subarray with the largest sum in an array using dynamic programming.
Coin Change Problem: Find the minimum number of coins required to make a given value using a set of denominations.
Rod Cutting Problem: Determine the maximum obtainable value by cutting a rod into smaller pieces with given lengths and values.
Matrix Chain Multiplication: Determine the most efficient way to multiply a chain of matrices to minimize the number of multiplications.
Longest Palindromic Subsequence: Find the length of the longest palindromic subsequence in a given string using dynamic programming.
Maximum Product Subarray: Find the maximum product of a subarray in an array using dynamic programming.
Unique Paths: Given a grid, find the number of unique paths from the top-left corner to the bottom-right corner using dynamic programming.
Word Break: Given a string and a dictionary of words, determine if the string can be segmented into a space-separated sequence of dictionary words using dynamic programming.
Longest Common Substring: Find the length of the longest common substring between two strings using dynamic programming.
House Robber: Determine the maximum amount of money that can be robbed from a row of houses without robbing adjacent houses using dynamic programming.
Maximum Length of Pair Chain: Given pairs of numbers, find the length of the longest chain of pairs where each pair (a, b) is in increasing order of the first element.
Best Time to Buy and Sell Stock: Find the maximum profit that can be obtained from buying and selling a stock at most once using dynamic programming.
Maximum Sum Increasing Subsequence: Find the maximum sum of an increasing subsequence in an array using dynamic programming.
Minimum Path Sum: Given a grid, find the minimum sum of a path from the top-left corner to the bottom-right corner using dynamic programming.
Climbing Stairs: Determine the number of distinct ways to climb to the top of a staircase with n steps, where you can climb either 1 or 2 steps at a time using dynamic programming.
Longest Valid Parentheses: Find the length of the longest valid parentheses substring in a given string using dynamic programming.
Maximum Profit with K Transactions: Given an array of stock prices and a maximum number of transactions allowed, find the maximum profit that can be obtained using dynamic programming.
Combination Sum: Given a set of candidate numbers and a target sum, find all unique combinations of candidates that sum to the target using dynamic programming.
Counting Bits: Given a non-negative integer n, count the number of bits set to 1 in the binary representation of all numbers from 0 to n using dynamic programming.
Decode Ways: Given a string containing encoded messages, determine the number of ways to decode the message using dynamic programming.
Palindrome Partitioning: Given a string, partition it into substrings such that each substring is a palindrome using dynamic programming.
Target Sum: Given an array of integers and a target sum, find the number of ways to obtain the target sum by assigning + or – signs to the integers using dynamic programming.
Longest Increasing Path in a Matrix: Find the length of the longest increasing path in a matrix using dynamic programming.
House Robber II: Determine the maximum amount of money that can be robbed from a circular row of houses using dynamic programming.
Perfect Squares: Given a positive integer n, find the least number of perfect square numbers that sum to n using dynamic programming.
Maximum Length of Repeated Subarray: Find the length of the longest common subarray between two arrays using dynamic programming.
Best Time to Buy and Sell Stock with Cooldown: Find the maximum profit that can be obtained from buying and selling stocks with a cooldown period using dynamic programming.
Longest Increasing Submatrix: Given a matrix, find the size of the largest submatrix where the elements are in increasing order using dynamic programming.
Longest Valid Parentheses II: Find the length of the longest valid parentheses substring in a given string that may contain characters other than ‘(‘ and ‘)’ using dynamic programming.
Combination Sum II: Given a collection of candidate numbers and a target sum, find all unique combinations that sum to the target, with each number used at most once using dynamic programming.
Paint House: Given the costs of painting each house with different colors, determine the minimum cost to paint all houses without adjacent houses having the same color using dynamic programming.
Partition Equal Subset Sum: Given a non-empty array of positive integers, determine if it can be partitioned into two subsets with equal sum using dynamic programming.
Longest Palindromic Substring: Find the longest palindromic substring in a given string using dynamic programming.
Unique Paths II: Given a grid with obstacles, find the number of unique paths from the top-left corner to the bottom-right corner, considering the obstacles using dynamic programming.
Count Different Palindromic Subsequences: Given a string, count the number of distinct palindromic subsequences in it using dynamic programming.
Burst Balloons: Given an array of balloons, each with a number representing the amount of coins, determine the maximum amount of coins that can be obtained by bursting the balloons using dynamic programming.
Decode Ways II: Given a string containing encoded messages, determine the number of ways to decode the message considering different decoding rules using dynamic programming.
Palindrome Partitioning II: Given a string, partition it into substrings such that each substring is a palindrome, and find the minimum number of cuts needed using dynamic programming.
Target Sum II: Given an array of integers and a target sum, find the number of ways to obtain the target sum by assigning +, -, *, or / signs to the integers using dynamic programming.
Longest Increasing Subsequence II: Find the length of the longest increasing subsequence in an array allowing duplicates using dynamic programming.
Largest Divisible Subset: Given a set of distinct positive integers, find the largest subset such that every pair of elements in the subset satisfies the condition a % b = 0 or b % a = 0 using dynamic programming.
Unique Binary Search Trees: Given an integer n, determine the number of unique binary search trees that can be formed with nodes numbered from 1 to n using dynamic programming.
Paint Fence: Given a fence with n posts and k colors, find the number of ways to paint the fence such that no more than two adjacent fence posts have the same color using dynamic programming.
Regular Expression Matching: Given a string s and a pattern p, determine if s matches p where the pattern can contain ‘.’ (matches any single character) and ‘*’ (matches zero or more of the preceding element) using dynamic programming.
Largest Sum of Averages: Given an array of numbers and an integer k, partition the array into k non-empty subsets such that the sum of averages of each subset is maximized using dynamic programming.
Coding Questions on backtracking
Permutations: Generate all possible permutations of a given set of elements.
Combination Sum: Find all combinations of numbers that add up to a target sum.
N-Queens Problem: Place N queens on an N×N chessboard such that no two queens threaten each other.
Word Search: Given a 2D board and a word, check if the word exists in the board.
Sudoku Solver: Solve a Sudoku puzzle.
Palindrome Partitioning: Partition a string into all possible palindromic substrings.
Generate Parentheses: Generate all valid parentheses combinations for a given number of pairs.
Letter Combinations of a Phone Number: Generate all possible letter combinations that the given number could represent on a phone keypad.
Combination Sum II: Find all unique combinations of numbers that add up to a target sum, each number can only be used once.
Subsets: Generate all possible subsets of a set of distinct integers.
Gray Code: Generate a sequence of n-bit gray codes.
Restore IP Addresses: Given a string containing only digits, restore it by returning all possible valid IP address combinations.
Word Break II: Given a non-empty string and a dictionary of words, add spaces in the string to construct sentences that can be formed using the words in the dictionary.
Subsets II: Generate all possible subsets of a set of integers that may contain duplicates.
Combinations: Generate all possible combinations of k numbers from 1 to n.
Palindrome Partitioning II: Partition a string into the fewest possible palindromic substrings.
Word Search II: Given a 2D board and a list of words, find all words in the board.
N-Queens II: Count the total number of distinct solutions to the N-Queens problem.
Sudoku Solver II: Solve a Sudoku puzzle with additional constraints.
Combination Sum III: Find all possible combinations of k numbers that add up to a given sum.
Permutation Sequence: Find the kth permutation sequence of the numbers from 1 to n.
Restore IP Addresses II: Given a string containing only digits, restore it by returning all possible valid IP address combinations.
Generate Parentheses II: Generate all valid parentheses combinations for a given number of pairs with additional conditions.
Combinations II: Generate all possible combinations of k numbers from 1 to n, with each combination containing unique elements.
Permutations II: Generate all possible permutations of a given set of elements with duplicates.
Combination Sum IV: Given an array of distinct integers and a target sum, find the number of possible combinations that add up to the target.
Palindrome Partitioning III: Partition a string into the fewest possible palindromic substrings with additional constraints.
Subsets III: Generate all possible subsets of a set of distinct integers with additional constraints.
Word Search III: Given a 2D board and a list of words, find all words in the board with additional constraints.
N-Queens III: Count the total number of distinct solutions to the N-Queens problem with additional constraints.
Sudoku Solver III: Solve a Sudoku puzzle with additional constraints and variations.
Combination Sum IV II: Given an array of distinct integers and a target sum, find the number of possible combinations that add up to the target with additional constraints.
Permutations III: Generate all possible permutations of a given set of elements with duplicates and additional constraints.
Generate Parentheses III: Generate all valid parentheses combinations for a given number of pairs with additional constraints.
Combinations III: Generate all possible combinations of k numbers from 1 to n, with each combination containing unique elements and additional constraints.
Palindrome Partitioning IV: Partition a string into the fewest possible palindromic substrings with additional constraints and variations.
Subsets IV: Generate all possible subsets of a set of distinct integers with additional constraints and variations.
Word Search IV: Given a 2D board and a list of words, find all words in the board with additional constraints and variations.
N-Queens IV: Count the total number of distinct solutions to the N-Queens problem with additional constraints and variations.
Sudoku Solver IV: Solve a Sudoku puzzle with additional constraints and variations.
Combination Sum V: Find all possible combinations of numbers that add up to a target sum with additional constraints and variations.
Permutations IV: Generate all possible permutations of a given set of elements with duplicates and additional constraints and variations.
Generate Parentheses IV: Generate all valid parentheses combinations for a given number of pairs with additional constraints and variations.
Combinations IV: Generate all possible combinations of k numbers from 1 to n, with each combination containing unique elements and additional constraints and variations.
Palindrome Partitioning V: Partition a string into the fewest possible palindromic substrings with additional constraints and variations.
Subsets V: Generate all possible subsets of a set of distinct integers with additional constraints and variations.
Word Search V: Given a 2D board and a list of words, find all words in the board with additional constraints and variations.
N-Queens V: Count the total number of distinct solutions to the N-Queens problem with additional constraints and variations.
Sudoku Solver V: Solve a Sudoku puzzle with additional constraints and variations.
Combination Sum VI: Find all possible combinations of numbers that add up to a target sum with additional constraints and variations.