Docsity

800+ Data-structure & Algorithm Interview Questions.pdf, Study notes of Computer science

Toggle sidebar
bg1
800+ Data Structures and Algorithms
Practice Problems:
Array
1. Find pair with given sum in the array
2. Check if subarray with 0 sum is exists or not
3. Print all sub-arrays with 0 sum
4. Sort binary array in linear time
5. Find a duplicate element in a limited range array
6. Find maximum length sub-array having given sum
7. Find maximum length sub-array having equal number of 0’s and 1’s
8. Find maximum product of two integers in an array
9. Sort an array containing 0’s, 1’s and 2’s (Dutch National Flag Problem)
10. In place merge two sorted arrays
11. Merge two arrays by satisfying given constraints
12. Find index of 0 to replace to get maximum length sequence of continuous ones
13. Shuffle a given array of elements (Fisher–Yates shuffle)
14. Rearrange the array with alternate high and low elements
15. Find equilibrium index of an array
16. Find largest sub-array formed by consecutive integers
17. Find majority element (Boyer–Moore Majority Vote Algorithm)
18. Move all zeros present in the array to the end
19. Replace each element of array with product of every other element without using /
operator
20. Find Longest Bitonic Subarray in an array
21. Longest Increasing Subsequence
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download 800+ Data-structure & Algorithm Interview Questions.pdf and more Study notes Computer science in PDF only on Docsity!

8 00+ Data Structures and Algorithms

Practice Problems:

Array

  1. Find pair with given sum in the array
  2. Check if subarray with 0 sum is exists or not
  3. Print all sub-arrays with 0 sum
  4. Sort binary array in linear time
  5. Find a duplicate element in a limited range array
  6. Find maximum length sub-array having given sum
  7. Find maximum length sub-array having equal number of 0’s and 1’s
  8. Find maximum product of two integers in an array
  9. Sort an array containing 0’s, 1’s and 2’s (Dutch National Flag Problem)
  10. In place merge two sorted arrays
  11. Merge two arrays by satisfying given constraints
  12. Find index of 0 to replace to get maximum length sequence of continuous ones
  13. Shuffle a given array of elements (Fisher–Yates shuffle)
  14. Rearrange the array with alternate high and low elements
  15. Find equilibrium index of an array
  16. Find largest sub-array formed by consecutive integers
  17. Find majority element (Boyer–Moore Majority Vote Algorithm)
  18. Move all zeros present in the array to the end
  19. Replace each element of array with product of every other element without using / operator
  20. Find Longest Bitonic Subarray in an array
  21. Longest Increasing Subsequence
  1. Find maximum difference between two elements in the array by satisfying given constraints
  2. Maximum Sum Subarray Problem (Kadane’s Algorithm)
  3. Print continuous subarray with maximum sum
  4. Maximum Sum Circular Subarray
  5. Find all distinct combinations of given length — I
  6. Find all distinct combinations of given length with repetition allowed
  7. Find maximum sequence of continuous 1’s formed by replacing at-most k zeroes by ones
  8. Find minimum sum subarray of given size k
  9. Find maximum product subarray in a given array
  10. Find subarray having given sum in given array of integers
  11. Find the length of smallest subarray whose sum of elements is greater than the given number
  12. Find largest number possible from set of given numbers
  13. Find the smallest window in array sorting which will make the entire array sorted
  14. Find maximum sum path involving elements of given arrays
  15. Maximum profit earned by buying and selling shares any number of times
  16. Trapping Rain Water within given set of bars
  17. Find minimum platforms needed in the station so to avoid any delay in arrival of any train
  18. Decode the array constructed from another array
  19. Sort an array using one swap
  20. Find Triplet with given sum in an array
  21. Length of longest continuous sequence with same sum in given binary arrays
  22. Reverse every consecutive m elements of the given subarray
  23. Maximum Product Subset Problem
  24. Find pairs with given difference k in the array
  25. Find pairs with given difference k in the array | Constant space solution
  26. 4 sum problem | Quadruplets with given sum
  27. Print all quadruplets with given sum | 4-sum problem extended
  28. Quickselect Algorithm
  29. Rearrange array such that A[A[i]] is set to i for every element A[i]
  30. Print all Triplets that forms Arithmetic Progression
  31. Print all Triplets that forms Geometric Progression
  32. Print all combination of numbers from 1 to n having sum n
  1. Count number of strictly increasing sub-arrays in an array
  2. Find duplicates within given range k in an array
  3. Longest Alternating Subarray Problem
  4. Find minimum range with at-least one element from each of the given arrays
  5. Find longest subsequence formed by consecutive integers
  6. Find all elements in an array that are greater than all elements present to their right
  7. Find missing number in array without using extra space
  8. Determine index of an element in given array which satisfies given constraints
  9. Find minimum moves required for converting a given array to an array of zeroes
  10. Left rotate an array
  11. Right rotate an array k times
  12. Find maximum profit earned from at most two stock transactions
  13. Find Frequency of each element in a sorted array containing duplicates
  14. Find Minimum and Maximum element in an array using minimum comparisons
  15. Difference between Subarray, Subsequence and Subset
  16. Find odd occurring element in an array in single traversal
  17. Find odd occurring element in logarithmic time
  18. Find two odd occurring elements in an array without using any extra space
  19. Check if given array represents min heap or not
  20. Find K’th smallest element in an array
  21. Find K’th largest element in an array
  22. Sort a K-Sorted Array
  23. Merge M sorted lists of variable length
  24. Find smallest range with at-least one element from each of the given lists
  25. Merge M sorted lists each containing N elements
  26. Find maximum sum of subsequence with no adjacent elements
  27. Find ways to calculate a target from elements of specified array
  28. Sort elements by their frequency and Index
  29. Sort an array based on order defined by another array
  30. Inversion Count of an array
  31. Segregate positive and negative integers in linear time
  32. Find number of rotations in a circularly sorted array
  33. Search an element in a circular sorted array
  34. Find first or last occurrence of a given number in a sorted array
  1. Count occurrences of a number in a sorted array with duplicates
  2. Find smallest missing element from a sorted array
  3. Find Floor and Ceil of a number in a sorted array
  4. Search in a nearly sorted array in logarithmic time
  5. Find number of 1’s in a sorted binary array
  6. Find Missing Term in a Sequence in Logarithmic time
  7. Find missing number and duplicate elements in an array
  8. Find the peak element in an array
  9. Find Floor and Ceil of a number in a sorted array (Recursive solution)
  10. Print all distinct subsets of a given set
  11. Find two duplicate elements in a limited range array (using XOR)
  12. Combinations of words formed by replacing given numbers with corresponding alphabets
  13. 0 – 1 Knapsack Problem
  14. Subset sum Problem
  15. Partition Problem
  16. 3-Partition Problem
  17. 3-partition problem extended | Print all partitions
  18. K-Partition Problem | Printing all Partitions
  19. Minimum Sum Partition Problem
  20. Rod Cutting
  21. Longest Alternating Subsequence Problem
  22. Coin change-making problem (unlimited supply of coins)
  23. Coin Change Problem — Find total number of ways to get the denomination of coins
  24. Find maximum profit earned from at most K stock transactions

String

  1. Check if given string is a rotated palindrome or not
  2. Longest Palindromic Substring (Non-DP Space Optimized Solution)
  3. Check if repeated subsequence is present in the string or not
  4. Check if strings can be derived from each other by circularly rotating them
  1. Remove all extra spaces from a string
  2. Remove adjacent duplicate characters from a string
  3. Find first non-repeating character in a string by doing only one traversal of it
  4. Find all N-digit strictly increasing numbers (Bottom-Up and Top-Down Approach)
  5. Find all N-digit binary numbers having more 1’s than 0’s for any prefix
  6. Find all N-digit numbers with given sum of digits
  7. Find all N-digit binary numbers with k-bits set where k ranges from 1 to N
  8. Find all N-digit binary numbers with equal sum of bits in its two halves
  9. Find all N-digit numbers with equal sum of digits at even and odd index
  10. Find all Lexicographic Permutations of a String
  11. Lexicographic Rank of a String
  12. Find all lexicographically previous permutations of a string sorted in descending order
  13. Replace all non-overlapping occurrences of the pattern
  14. Introduction to Pattern Matching
  15. Implementation of KMP Algorithm
  16. Reverse String without using Recursion
  17. Reverse given string using Recursion
  18. Determine if characters of a String follow a specified order or not
  19. In-place remove all adjacent duplicates from the given string
  20. Check if given sentence is syntactically correct or not
  21. Find all Permutations of a given string
  22. Find first k non-repeating characters in a string in single traversal
  23. Check if given string is interleaving of two other given strings
  24. Decode the given sequence to construct minimum number without repeated digits
  25. Combinations of words formed by replacing given numbers with corresponding alphabets
  26. Count number of times a pattern appears in given string as a subsequence
  27. Check if a string matches with a given wildcard pattern
  28. Find all words matching a pattern in the given dictionary
  29. The Levenshtein Distance (Edit Distance) Problem
  30. Longest Common Subsequence Problem
  31. Longest Repeated Subsequence Problem
  32. Longest Palindromic Subsequence using Dynamic Programming
  33. Longest Common Substring Problem
  34. Shortest Common Supersequence Problem
  1. Word Break Problem
  2. Wildcard Pattern Matching
  3. Find minimum cuts needed for palindromic partition of a string
  4. Check if a string is K-Palindrome or not
  5. Find shortest route in a device to construct the given string
  6. Find minimum number possible by doing at-most K swaps
  7. Determine if a pattern matches with a string or not
  8. Find minimum number of deletions required to convert a string into palindrome

Backtracking

  1. Print all possible solutions to N Queens Problem
  2. Print all Possible Knight’s Tours in a chessboard
  3. Find Shortest Path in Maze
  4. Find Longest Possible Route in a Matrix
  5. Find path from source to destination in a matrix that satisfies given constraints
  6. Find total number of unique paths in a maze from source to destination
  7. Print All Hamiltonian Path present in a graph
  8. Print all k-colorable configurations of the graph (Vertex coloring of graph)
  9. Find all Permutations of a given string
  10. All combinations of elements satisfying given constraints
  11. Find all binary strings that can be formed from given wildcard pattern
  12. K-Partition Problem | Printing all Partitions
  13. Magnet Puzzle
  14. Find ways to calculate a target from elements of specified array
  15. Find minimum number possible by doing at-most K swaps
  16. Determine if a pattern matches with a string or not
  17. Generate list of possible words from a character matrix
  18. Find the path between given vertices in a directed graph
  19. Find all Possible Topological Orderings of a DAG
  20. Print all shortest routes in a rectangular grid
  1. Find missing number and duplicate elements in an array
  2. Circular shift on binary representation of an integer by k positions
  3. Compute modulus division without division and modulo operator
  4. Solve given set of problems without using multiplication or division operators
  5. Find XOR of two numbers without using XOR operator
  6. Generate power set of a given set
  7. Huffman Coding
  8. Find missing number in array without using extra space
  9. Find odd occurring element in logarithmic time
  10. Find all odd occurring elements in an array having limited range of elements

Binary Tree

  1. Check if two given binary trees are identical or not
  2. Calculate height of a binary tree
  3. Delete given Binary Tree
  4. Inorder Tree Traversal (Iterative & Recursive Implementation)
  5. Preorder Tree Traversal (Iterative & Recursive Implementation)
  6. Postorder Tree Traversal (Iterative & Recursive Implementation)
  7. Level Order Traversal of Binary Tree
  8. Spiral Order Traversal of Binary Tree
  9. Reverse Level Order Traversal of Binary Tree
  10. Print all nodes of a given binary tree in specific order
  11. Print left view of binary tree
  12. Print Bottom View of Binary Tree
  13. Print Top View of Binary Tree
  14. Find next node in same level for given node in a binary tree
  15. Check if given binary tree is complete binary tree or not
  16. In-place convert given binary tree to its sum tree
  17. Determine if given two nodes are cousins of each other
  18. Print cousins of given node in a binary tree
  1. Check if given binary tree is a sum tree or not
  2. Combinations of words formed by replacing given numbers with corresponding alphabets
  3. Determine if given binary tree is a subtree of another binary tree or not
  4. Find diameter of a binary tree
  5. Check if given binary Tree has symmetric structure or not
  6. Convert binary tree to its mirror
  7. Check if binary tree can be converted to another by doing any no. of swaps of left & right child
  8. Find Lowest Common Ancestor (LCA) of two nodes in a binary tree
  9. Print all paths from root to leaf nodes in a binary tree
  10. Find ancestors of given node in a Binary Tree
  11. Find the distance between given pairs of nodes in a binary tree
  12. Find Vertical Sum in a given Binary Tree
  13. Perform vertical traversal of a binary tree — I
  14. Perform vertical traversal of a binary tree — II
  15. Print corner nodes of every level in binary tree
  16. Find the diagonal sum of given binary tree
  17. Print Diagonal Traversal of Binary Tree
  18. In-place convert Binary Tree to Doubly Linked List
  19. Sink nodes containing zero to the bottom of the binary tree
  20. Convert given binary tree to full tree by removing half nodes
  21. Truncate given binary tree to remove nodes which lie on a path having sum less than K
  22. Find maximum sum root-to-leaf path in a binary tree
  23. Check if given binary tree is height balanced or not
  24. Find maximum width of given binary tree
  25. Convert normal binary tree to Left-child right-sibling binary tree
  26. Determine if given Binary Tree is a BST or not
  27. Convert a Binary Tree to BST by maintaining its original structure
  28. Invert a Binary Tree
  29. Print Right View of a Binary Tree
  30. Print all paths from leaf to root node in given binary tree
  31. Iteratively print leaf to root path for every leaf node in a binary tree
  32. Build Binary Tree from given Parent array
  33. Find all nodes at given distance from leaf nodes in a binary tree
  34. Count all subtrees having same value of nodes in a binary tree
  1. Construct balanced BST from given keys
  2. Determine if given Binary Tree is a BST or not
  3. Check if given keys represents same BSTs or not without building the BST
  4. Find inorder predecessor for given key in a BST
  5. Find Lowest Common Ancestor (LCA) of two nodes in a Binary Search Tree
  6. Find K’th smallest and K’th largest element in BST
  7. Floor and Ceil in a Binary Search Tree
  8. Find optimal cost to construct binary search tree
  9. Convert a Binary Tree to BST by maintaining its original structure
  10. Remove nodes from BST that have keys outside the valid range
  11. Find a pair with given sum in a BST
  12. Find inorder successor for given key in a BST
  13. Replace every element of an array with the least greater element on its right
  14. Fix a binary tree that is only one swap away from becoming a BST
  15. Update every key in BST to contain sum of all greater keys
  16. Check if a given sequence represents preorder traversal of a BST
  17. Build a Binary Search Tree from a Postorder Sequence
  18. Build a Binary Search Tree from a Preorder Sequence
  19. Find a triplet with given sum in a BST
  20. Count subtrees in a BST whose nodes lies within a given range
  21. Merge two BSTs into a doubly linked list in sorted order
  22. Construct a height-balanced BST from an unbalanced BST
  23. Find the size of the largest BST in a Binary Tree
  24. Convert a Binary Search Tree into a Min Heap
  25. Construct a Height-Balanced BST from a Sorted Doubly Linked List

Divide & Conquer

  1. Binary Search Algorithm
  2. Find number of rotations in a circularly sorted array
  3. Search an element in a circular sorted array
  1. Find first or last occurrence of a given number in a sorted array
  2. Count occurrences of a number in a sorted array with duplicates
  3. Find smallest missing element from a sorted array
  4. Find Floor and Ceil of a number in a sorted array
  5. Search in a nearly sorted array in logarithmic time
  6. Find number of 1’s in a sorted binary array
  7. Find the peak element in an array
  8. Maximum Sum Subarray using Divide & Conquer
  9. Efficiently implement a power function
  10. Find Missing Term in a Sequence in Logarithmic time
  11. Division of Two Numbers using Binary Search Algorithm
  12. Find Floor and Ceil of a number in a sorted array (Recursive solution)
  13. Find Frequency of each element in a sorted array containing duplicates
  14. Find odd occurring element in logarithmic time
  15. Ternary Search vs Binary search
  16. Exponential search
  17. Unbounded Binary Search
  18. Interpolation search
  19. Merge Sort Algorithm
  20. QuickSort Algorithm

Dynamic Programming

  1. Introduction to Dynamic Programming
  2. Longest Common Subsequence Problem
  3. Longest Common Subsequence | Space optimized version
  4. Longest Common Subsequence of K-sequences
  5. Longest Common Subsequence | Finding all LCS
  6. Longest Common Substring Problem
  7. Longest Palindromic Subsequence Problem
  8. Longest Repeated Subsequence Problem
  1. Wildcard Pattern Matching
  2. Find number of ways to fill a N x 4 matrix with 1 x 4 tiles
  3. Ways to reach the bottom-right corner of a matrix with exactly k turns allowed
  4. Weighted Interval Scheduling Problem
  5. Box Stacking Problem
  6. Find total ways to reach the n’th stair with at-most m steps
  7. Find total ways to reach the n’th stair from the bottom
  8. Activity Selection Problem
  9. Find minimum number of deletions required to convert a string into palindrome
  10. Calculate minimum cost to reach destination city from source city
  11. Pots of Gold Game Problem
  12. Find minimum cuts needed for palindromic partition of a string
  13. Weighted Interval Scheduling using LIS algorithm
  14. Find minimum jumps required to reach the destination
  15. Find probability that a person is alive after taking N steps on the island
  16. Find maximum sum of subsequence with no adjacent elements
  17. Maximum Length Snake Sequence
  18. Calculate size of the largest plus of 1’s in binary matrix
  19. Longest Increasing Subsequence using LCS
  20. Find maximum profit earned from at most K stock transactions
  21. Count all paths in a matrix from first cell to last cell
  22. Check if a string matches with a given wildcard pattern
  23. Check if given string is interleaving of two other given strings
  24. Find all employees who directly or indirectly reports to a manager
  25. Find optimal cost to construct binary search tree
  26. Find maximum sum of subsequence with no adjacent elements
  27. Maximum Sum Subarray Problem (Kadane’s Algorithm)
  28. Longest Alternating Subarray Problem
  29. Collect maximum value of coins in a matrix
  30. Find length of longest path in the matrix with consecutive characters
  31. Find ways to calculate a target from elements of specified array
  32. Calculate sum of all elements in a sub-matrix in constant time
  33. Find maximum sum K x K sub-matrix in a given M x N matrix
  34. Find maximum sum submatrix present in a given matrix
  1. Single-Source Shortest Paths — Bellman Ford Algorithm
  2. All-Pairs Shortest Paths — Floyd Warshall Algorithm

Graph

  1. Terminology and Representations of Graphs
  2. Graph Implementation — C, C++, C++ (STL), Java (Collections), Python
  3. Breadth First Search (BFS) Algorithm
  4. Depth First Search (DFS) Algorithm
  5. Depth first search (DFS) vs Breadth first search (BFS)
  6. Arrival and Departure Time of Vertices in DFS
  7. Types of edges involved in DFS and relation between them
  8. Bipartite Graph
  9. Determine if a given graph is Bipartite Graph using DFS
  10. Snake and Ladder Problem
  11. Topological Sorting in a DAG
  12. Kahn’s Topological Sort Algorithm
  13. Transitive Closure of a Graph
  14. Check if an undirected graph contains cycle or not
  15. Total paths in given digraph from given source to destination having exactly m edges
  16. Determine if an undirected graph is a Tree (Acyclic Connected Graph)
  17. 2-Edge Connectivity in the graph
  18. 2-Vertex Connectivity in the graph
  19. Check if given digraph is a DAG (Directed Acyclic Graph) or not
  20. Disjoint-Set Data Structure (Union-Find Algorithm)
  21. Chess Knight Problem — Find Shortest path from source to destination
  22. Check if given Graph is Strongly Connected or not
  23. Check if given Graph is Strongly Connected or not using one DFS Traversal
  24. Union-Find Algorithm for Cycle Detection in undirected graph
  25. Kruskal’s Algorithm for finding Minimum Spanning Tree
  26. Single-Source Shortest Paths — Dijkstra’s Algorithm
  1. Convert Max Heap to Min Heap in linear time
  2. Find K’th largest element in an array
  3. Sort a K-Sorted Array
  4. Merge M sorted lists of variable length
  5. Merge K sorted linked lists
  6. Find K’th smallest element in an array
  7. Find smallest range with at-least one element from each of the given lists
  8. Merge M sorted lists each containing N elements
  9. Find first k non-repeating characters in a string in single traversal
  10. Find first k maximum occurring words in given set of strings
  11. Implementation of Treap Data Structure (Insert, Search and Delete)
  12. Convert a Binary Search Tree into a Min Heap
  13. Check if a binary tree is a min-heap or not
  14. Huffman Coding
  15. External Merge Sort Algorithm

Linked List

  1. Introduction to Linked Lists
  2. Linked List Implementation — C, C++, Java, Python
  3. Linked List | Insertion at Tail
  4. Static Linked List
  5. Clone given Linked List
  6. Delete Linked List
  7. Pop operation in linked list
  8. Insert given node into the correct sorted position in the given sorted linked list
  9. Rearrange linked list in increasing order (Sort linked list)
  10. Split the nodes of the given linked list into front and back halves
  11. Remove duplicates from a sorted linked list
  12. Move front node of the given list to the front of the another list
  13. Move even nodes to the end of the list in reverse order
  14. Split given linked list into two lists where each list containing alternating elements from it
  15. Construct a linked list by merging alternate nodes of two given lists
  16. Merge Sort Algorithm for Singly Linked List
  1. Merge two sorted linked lists into one
  2. Merge K sorted linked lists
  3. Intersection of two given sorted linked lists
  4. Reverse Linked List (Iterative Solution)
  5. Reverse Linked List (Recursive Solution)
  6. Reverse every group of k nodes in given linked list
  7. Find K’th node from the end in a linked list
  8. Merge alternate nodes of two linked lists into the first list
  9. Merge two sorted linked lists from their end
  10. Delete every N nodes in a linked list after skipping M nodes
  11. Rearrange linked list in specific manner in linear time
  12. Check if linked list is palindrome or not
  13. Move last node to front in a given Linked List
  14. Rearrange the linked list in specific manner
  15. Detect Cycle in a linked list (Floyd’s Cycle Detection Algorithm)
  16. Sort linked list containing 0’s, 1’s and 2’s
  17. Implement Stack using Linked List
  18. Implement Queue using Linked List
  19. Remove duplicates from a linked list
  20. Rearrange the linked list so that it has alternating high, low values
  21. Rearrange a Linked List by Separating Odd Nodes from the Even Ones
  22. Calculate height of a binary tree with leaf nodes forming a circular doubly linked list
  23. XOR Linked List: Overview and Implementation
  24. Convert a multilevel linked list to a singly linked list
  25. Recursively check if linked list of characters is palindrome or not
  26. Merge two BSTs into a doubly linked list in sorted order
  27. Remove redundant nodes from a path formed by a linked list
  28. Add a single-digit number to a linked list representing a number
  29. Reverse every alternate group of k nodes in a linked list
  30. Determine if a given linked list is a palindrome or not
  31. Sort a Doubly Linked List using Merge Sort
  32. Reverse a Doubly Linked List
  33. Pairwise swap adjacent nodes of a linked list
  34. Flatten a linked list