Data Structures and Algorithms Problems

Array

     

  1. Find pair with given sum in the array
     
  2. Find sub-array with 0 sum
     
  3. Sort binary array in linear time
     
  4. Find a duplicate element in a limited range array
     
  5. Find largest sub-array formed by consecutive integers
     
  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. Sort an array containing 0’s, 1’s and 2’s (Dutch national flag problem)
     
  9. Inplace merge two sorted arrays
     
  10. Merge two arrays by satisfying given constraints
     
  11. Find index of 0 to replaced to get maximum length sequence of continuous ones
     
  12. Find maximum product of two integers in an array
     
  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 majority element in an array (Boyer–Moore majority vote algorithm)
     
  17. Move all zeros present in the array to the end
     
  18. Replace each element of array with product of every other element without using division operator
     
  19. Find Longest Bitonic Subarray in an array
     
  20. Find maximum difference between two elements in the array by satisfying given constraints
     
  21. Maximum subarray problem (Kadane’s algorithm)
     
  22. Maximum Sum Circular Subarray
     
  23. Find all distinct combinations of given length
     
  24. Find all distinct combinations of given length with repetition allowed
     
  25. Find maximum sequence of continuous 1’s formed by replacing at-most k zeroes by ones
     
  26. Find minimum sum subarray of given size k
     
  27. Find subarray having given sum in given array of integers
     
  28. Find the length of smallest subarray whose sum of elements is greater than the given number
     
  29. Find largest number possible from set of given numbers
     
  30. Find the smallest window in array sorting which will make the entire array sorted
     
  31. Find maximum sum path involving elements of given arrays
     
  32. Maximum profit earned by buying and selling shares any number of times
     
  33. Trapping Rain Water within given set of bars
     
  34. Longest Increasing Subsequence
     
  35. Find maximum product subarray in a given array
     
  36. Find maximum sum of subsequence with no adjacent elements
     
  37. Find minimum platforms needed in the station so to avoid any delay in arrival of any train
     
  38. Decode the array constructed from another array
     
  39. Sort an array using one swap
     
  40. Find Triplet with given sum in an array
     
  41. Length of longest continuous sequence with same sum in given binary arrays
     
     
  42. Merging Overlapping Intervals
     
  43. Activity Selection Problem
     
  44. Job Sequencing Problem with Deadlines
     
  45. Introduction to Priority Queues using Binary Heaps
     
  46. Min Heap and Max Heap Implementation in C++
     
  47. Heap Sort
     
  48. Check if given array represents min heap or not
     
  49. Convert Max Heap to Min Heap in linear time
     
  50. Find K’th largest element in an array
     
  51. Sort a K-Sorted Array
     
  52. Merge M sorted lists of variable length
     
  53. Find K’th smallest element in an array
     
  54. Find smallest range with at-least one element from each of the given lists
     
  55. Merge M sorted lists each containing N elements
     
  56. Insertion sort | Iterative & Recursive
     
  57. Selection sort | Iterative & Recursive
     
  58. Bubble sort | Iterative & Recursive
     
  59. Merge Sort Algorithm
     
  60. Quicksort Algorithm
     
  61. Iterative Implementation of Quicksort
     
  62. Hybrid QuickSort
     
  63. Quicksort using Dutch National Flag Algorithm
     
  64. Quick Sort using Hoare’s Partitioning scheme
     
  65. External merge sort
     
  66. Custom Sort | Sort elements by their frequency and Index
     
  67. Custom Sort | Sort elements of the array by order of elements defined by the second array
     
  68. Inversion Count of an array
     
  69. Segregate positive and negative integers in linear time
     
  70. Binary Search
     
  71. Ternary Search vs Binary search
     
  72. Interpolation search
     
  73. Exponential search
     
  74. Find number of rotations in a circularly sorted array
     
  75. Search an element in a circular sorted array
     
  76. Find first or last occurrence of a given number in a sorted array
     
  77. Count occurrences of a number in a sorted array with duplicates
     
  78. Find smallest missing element from a sorted array
     
  79. Find Floor and Ceil of a number in a sorted array
     
  80. Search in a nearly sorted array in O(logn) time
     
  81. Find number of 1’s in a sorted binary array
     
  82. Find the peak element in an array
     
  83. Maximum Sum Subarray using Divide & Conquer
     
  84. Find Minimum and Maximum element in an array using minimum comparisons
     
  85. Matrix Chain Multiplication
     
  86. 0-1 Knapsack problem
     
  87. Maximize value of the expression
     
  88. Partition problem
     
  89. Subset sum problem
     
  90. Minimum Sum Partition problem
     
  91. Rod Cutting
     
  92. Coin change-making problem (unlimited supply of coins)
     
  93. Coin Change Problem (Total number of ways to get the denomination of coins)
     
  94. Longest alternating subsequence
     
  95. Combinations of words formed by replacing given numbers with corresponding alphabets
     
  96. Decode the given sequence to construct minimum number without repeated digits
     
  97. All combinations of elements satisfying given constraints
     

Backtracking

Bit Manipulation

Binary Tree

 

  1. Check if two given binary trees are identical or not | Iterative & Recursive
     
  2. Calculate height of a binary tree | Iterative & Recursive
     
  3. Delete given Binary Tree | Iterative & Recursive
     
  4. Inorder Tree Traversal | Iterative & Recursive
     
  5. Preorder Tree Traversal | Iterative & Recursive
     
  6. Postorder Tree Traversal | Iterative & Recursive
     
  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. Determine if given two nodes are cousins of each other
     
  17. Print cousins of given node in a binary tree
     
  18. In-place convert given binary tree to its sum tree
     
  19. Check if given binary tree is a sum tree or not
     
  20. Combinations of words formed by replacing given numbers with corresponding alphabets
     
  21. Determine if given binary tree is a subtree of another binary tree or not
     
  22. Find diameter of a binary tree
     
  23. Check if given binary Tree has symmetric structure or not
     
  24. Convert binary tree to its mirror
     
  25. Check if binary tree can be converted to another by doing any no. of swaps of left & right child
     
  26. Find Lowest Common Ancestor (LCA) of two nodes in a binary tree
     
  27. Print all paths from root to leaf nodes in given binary tree
     
  28. Find ancestors of given node in a Binary Tree
     
  29. Find the distance between given pairs of nodes in a binary tree
     
  30. Find Vertical Sum in a given Binary Tree
     
  31. Print nodes in vertical order of a given Binary Tree (Vertical Traversal)
     
  32. Find the diagonal sum of given binary tree
     
  33. Print Diagonal Traversal of Binary Tree
     
  34. Print corner nodes of every level in binary tree
     
  35. In-place convert convert given Binary Tree to Doubly Linked List
     
  36. Sink nodes containing zero to the bottom of the binary tree
     
  37. Convert given binary tree to full tree by removing half nodes
     
  38. Truncate given binary tree to remove nodes which lie on a path having sum less than K
     
  39. Find maximum sum root-to-leaf path in a binary tree
     
  40. Check if given binary tree is height balanced or not
     
  41. Convert normal binary tree to Left-child right-sibling binary tree
     
  42. Determine if given Binary Tree is a BST or not
     
  43. Convert a Binary Tree to BST by maintaining its original structure
     

BST

Divide & Conquer

Dynamic Programming

 

  1. Introduction to Dynamic Programming
     
  2. Longest Common Subsequence | Introduction & LCS Length
     
  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 using Dynamic Programming
     
  8. Longest Repeated Subsequence problem
     
  9. Implement Diff Utility
     
  10. Shortest Common Supersequence | Introduction & SCS Length
     
  11. Shortest Common Supersequence | Finding all SCS
     
  12. Shortest Common Supersequence | Using LCS
     
  13. Longest Increasing Subsequence using Dynamic Programming
     
  14. Longest Bitonic Subsequence
     
  15. Increasing Subsequence with Maximum Sum
     
  16. The Levenshtein distance (Edit distance) problem
     
  17. Find size of largest square sub-matrix of 1’s present in given binary matrix
     
  18. Matrix Chain Multiplication
     
  19. Find the minimum cost to reach last cell of the matrix from its first cell
     
  20. Find longest sequence formed by adjacent numbers in the matrix
     
  21. Count number of paths in a matrix with given cost to reach destination cell
     
  22. 0-1 Knapsack problem
     
  23. Maximize value of the expression
     
  24. Partition problem
     
  25. Subset sum problem
     
  26. Minimum Sum Partition problem
     
  27. Find all N-digit binary strings without any consecutive 1’s
     
  28. Rod Cutting
     
  29. Maximum Product Rod Cutting
     
  30. Coin change-making problem (unlimited supply of coins)
     
  31. Coin Change Problem – Find total number of ways to get the denomination of coins
     
  32. Longest alternating subsequence
     
  33. Count number of times a pattern appears in given string as a subsequence
     
  34. Collect maximum points in a matrix by satisfying given constraints
     
  35. Count total possible combinations of N-digit numbers in a mobile keypad
     
  36. Find optimal cost to construct binary search tree
     
  37. Word Break Problem
     
  38. Wildcard Pattern Matching
     
     
  39. Find probability that a person is alive after taking N steps on the island
     
  40. Calculate sum of all elements in a sub-matrix in constant time
     
  41. Find maximum sum K x K sub-matrix in a given M x N matrix
     
  42. Find maximum sum submatrix present in a given matrix
     
  43. Find maximum sum of subsequence with no adjacent elements
     
  44. Maximum subarray problem (Kadane’s algorithm)
     
  45. Single-Source Shortest Paths – Bellman Ford Algorithm
     
  46. All-Pairs Shortest Paths – Floyd Warshall Algorithm
     

Graphs

 

  1. Terminology and Representations of Graphs
     
  2. Graph Implementation using STL
     
  3. Graph Implementation in C++ without using STL
     
  4. Breadth First Search (BFS) | Iterative & Recursive Implementation
     
  5. Depth First Search (DFS) | Iterative & Recursive Implementation
     
  6. Arrival and Departure Time of Vertices in DFS
     
  7. Types of edges involved in DFS and relation between them
     
  8. Bipartite Graph
     
  9. Minimum number of throws required to win Snake and Ladder game
     
  10. Topological Sorting in a DAG
     
  11. Transitive Closure of a Graph
     
  12. Check if an undirected graph contains cycle or not
     
  13. Total paths in given digraph from given source to destination having exactly m edges
     
  14. Determine if an undirected graph is a Tree (Acyclic Connected Graph)
     
  15. 2-Edge Connectivity in the graph
     
  16. 2-Vertex Connectivity in the graph
     
  17. Check if given digraph is a DAG (Directed Acyclic Graph) or not
     
  18. Disjoint-Set Data Structure (Union-Find Algorithm)
     
  19. Chess Knight Problem – Find Shortest path from source to destination
     
  20. Check if given Graph is Strongly Connected or not
     
  21. Check if given Graph is Strongly Connected or not using one DFS Traversal
     
  22. Union-Find Algorithm for Cycle Detection in undirected graph
     
  23. Kruskal’s Algorithm for finding Minimum Spanning Tree
     
  24. Single-Source Shortest Paths – Dijkstra’s Algorithm
     
  25. Single-Source Shortest Paths – Bellman Ford Algorithm
     
  26. All-Pairs Shortest Paths – Floyd Warshall Algorithm
     
     
  27. Print all k-colorable configurations of the graph (Vertex coloring of graph)
     
  28. Print All Hamiltonian Path present in a graph
     
  29. Greedy coloring of graph
     

Heap

Linked List

 

  1. Introduction to Linked Lists
     
  2. Linked List Implementation | Part 1
     
  3. Linked List Implementation | Part 2
     
  4. Static Linked List in C
     
  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. Given a linked list, change it to be in sorted order
     
  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 given sorted linked lists into one
     
  17. Merge Sort Algorithm for Singly Linked List
     
  18. Intersection of two given sorted linked lists
     
  19. Reverse linked list | Part 1 (Iterative Solution)
     
  20. Reverse linked list | Part 2 (Recursive Solution)
     
  21. Reverse every group of k nodes in given linked list
     
  22. Find K’th node from the end in a linked list
     
  23. Merge alternate nodes of two linked lists into the first list
     
  24. Merge two sorted linked lists from their end
     
  25. Delete every N nodes in a linked list after skipping M nodes
     
  26. Rearrange linked list in specific manner in linear time
     
  27. Check if linked list is palindrome or not
     
  28. Move last node to front in a given Linked List
     
  29. Rearrange the linked list in specific manner
     
  30. Detect Cycle in a linked list (Floyd’s Cycle Detection Algorithm)
     
  31. Sort linked list containing 0’s, 1’s and 2’s
     

Matrix

 

  1. Print Matrix in Spiral Order
     
  2. Create Spiral Matrix from given array
     
  3. Shift all matrix elements by 1 in Spiral Order
     
  4. Find Shortest path from source to destination in a matrix that satisfies given constraints
     
  5. Change all elements of row i and column j in a matrix to 0 if cell (i, j) has value 0
     
  6. Print diagonal elements of the matrix having positive slope
     
  7. Find all paths from first cell to last cell of a matrix
     
  8. Replace all occurrences of 0 that are not surrounded by 1 in a binary matrix
     
  9. In-place rotate the matrix by 90 degrees in clock-wise direction
     
  10. Count negative elements present in sorted matrix in linear time
     
  11. Report all occurrences of an element in row wise and column wise sorted matrix in linear time
     
  12. Calculate sum of all elements in a sub-matrix in constant time
     
  13. Find maximum sum K x K sub-matrix in a given M x N matrix
     
  14. Find maximum sum submatrix present in a given matrix
     
  15. Find probability that a person is alive after taking N steps on the island
     
  16. Count the number of islands
     
  17. Flood fill Algorithm
     
  18. Find shortest safe route in a field with sensors present
     
  19. Find all occurrences of given string in a character matrix
     
  20. Shortest path in a Maze | Lee algorithm
     
     
  21. Travelling Salesman Problem using Branch and Bound
     
  22. Collect maximum points in a matrix by satisfying given constraints
     
  23. Count number of paths in a matrix with given cost to reach destination cell
     
  24. Find longest sequence formed by adjacent numbers in the matrix
     
  25. Find the minimum cost to reach last cell of the matrix from its first cell
     
  26. Matrix Chain Multiplication
     
  27. Find size of largest square sub-matrix of 1’s present in given binary matrix
     
  28. Chess Knight Problem – Find Shortest path from source to destination
     
  29. Find Duplicate rows in a binary matrix
     
  30. Print all possible solutions to N Queens problem
     
  31. Print all Possible Knight’s Tours in a chessboard
     
  32. Find Shortest Path in Maze
     
  33. Find Longest Possible Route in a Matrix
     

Queue

Sorting

 

  1. Insertion sort | Iterative & Recursive
     
  2. Selection sort | Iterative & Recursive
     
  3. Bubble sort | Iterative & Recursive
     
  4. Merge Sort Algorithm
     
  5. Quicksort Algorithm
     
  6. Iterative Implementation of Quicksort
     
  7. Hybrid QuickSort
     
  8. Quicksort using Dutch National Flag Algorithm
     
  9. Quick Sort using Hoare’s Partitioning scheme
     
  10. External merge sort
     
  11. Custom Sort | Sort elements by their frequency and Index
     
  12. Custom Sort | Sort elements of the array by order of elements defined by the second array
     
  13. Inversion Count of an array
     
  14. Segregate positive and negative integers in linear time
     
     
  15. Find the smallest window in array sorting which will make the entire array sorted
     
  16. Find largest number possible from set of given numbers
     
  17. Move all zeros present in the array to the end
     
  18. Sort binary array in linear time
     
  19. Sort linked list containing 0’s, 1’s and 2’s
     
  20. Merge Sort Algorithm for Singly Linked List
     
  21. Group anagrams together from given list of words
     
  22. Activity Selection Problem
     
  23. Lexicographic sorting of given set of keys
     
  24. Heap Sort
     
  25. Merge M sorted lists of variable length
     
  26. Merge M sorted lists each containing N elements
     
  27. Find all palindromic permutations of a string
     
  28. Find all lexicographically next permutations of a string sorted in ascending order
     
  29. Merge two sorted linked lists from their end
     
  30. Sort an array containing 0’s, 1’s and 2’s (Dutch national flag problem)
     
  31. Find pair with given sum in the array
     
  32. Inplace merge two sorted arrays
     
  33. Merge two arrays by satisfying given constraints
     
  34. Find maximum product of two integers in an array
     
  35. Find all distinct combinations of given length
     
  36. Find all distinct combinations of given length with repetition allowed
     
  37. Merging Overlapping Intervals
     

Stack

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
     
  5. Check if given set of moves is circular or not
     
  6. Convert given number into corresponding excel column name
     
  7. Determine if two strings are anagram or not
     
  8. Find all binary strings that can be formed from given wildcard pattern
     
  9. Find all interleavings of given strings
     
  10. Isomorphic Strings
     
  11. Find all possible palindromic substrings in a string
     
  12. Find all possible combinations of words formed from mobile keypad
     
  13. Find all possible combinations by replacing given digits with characters of the corresponding list
     
  14. Find all words from given list that follows same order of characters as given pattern
     
  15. Find first k non-repeating characters in a string in single traversal
     
  16. Group anagrams together from given list of words
     
  17. Introduction to Pattern Matching
     
  18. Inplace remove all occurrences of ‘AB’ and ‘C’ from the string
     
  19. Longest even length palidromic sum substring
     
  20. Print string in zig-zag form in k rows
     
  21. Reverse given text without reversing the individual words
     
  22. Run Length Encoding (RLE) data compression algorithm
     
  23. Validate an IP address
     
  24. Find the longest substring of given string containing k distinct characters
     
  25. Find all palindromic permutations of a string
     
  26. Find all substrings of a string that are permutation of a given string
     
  27. Find the longest substring of given string containing all distinct characters
     
  28. Find all Permutations of a given string
     
  29. Find all lexicographically next permutations of a string sorted in ascending order
     
  30. Find Lexicographically minimal string rotation
     
  31. Find all strings of given length containing balanced parentheses
     
  32. Find all N-digit binary numbers with k-bits set where k ranges from 1 to N
     
  33. Generate binary numbers between 1 to N
     
  34. Find all combinations of non-overlapping substrings of a string
     
  35. Check if given sentence is syntactically correct or not
     
  36. Find all N-digit strictly increasing numbers (Bottom-Up and Top-Down Approach)
     
  37. Calculate rank of given string among all its lexicographically sorted permutations
     
     
  38. Combinations of words formed by replacing given numbers with corresponding alphabets
     
  39. Word Break Problem
     
  40. Wildcard Pattern Matching
     
  41. Count number of times a pattern appears in given string as a subsequence
     
  42. The Levenshtein distance (Edit distance) problem
     
  43. Longest Common Subsequence | Introduction & LCS Length
     
  44. Longest Common Subsequence | Space optimized version
     
  45. Longest Common Subsequence of K-sequences
     
  46. Longest Common Subsequence | Finding all LCS
     
  47. Longest Repeated Subsequence problem
     
  48. Longest Palindromic Subsequence using Dynamic Programming
     
  49. Longest Common Substring problem
     
  50. Shortest Common Supersequence | Introduction & SCS Length
     
  51. Shortest Common Supersequence | Finding all SCS
     
  52. Shortest Common Supersequence | Using LCS
     
  53. Implement Diff Utility
     

Trie

Greedy

Puzzles

STL

Recursion

Hashing

 
  Other links:
 




 
 

Thank you all being with us. 🙂