The Standard Template Library (STL) is a library for the C++ programming language. The STL provides many useful algorithms and containers. The Containers are objects that store data. We have taken the help of the following containers to solve mentioned problems:
vector, list, queue, priority_queue, stack, set, map, multimap, unordered_set, unordered_multiset, unordered_map, unordered_multimap
We have avoided using STL algorithms as the main purpose of these problems is to improve your coding skills and using in-built algorithms will do no good. Nevertheless, we have still used the following common algorithms at several places:
min, max, swap, sort, next_permutation, binary_search, rotate, reverse
Priority Queue (Heap):
- Min Heap and Max Heap Implementation in C++Beginner
- Find k’th largest element in an arrayMedium
- Sort a k-sorted arrayMedium
- Find k’th smallest element in an arrayMedium
- Find the smallest range with at least one element from each of the given listsHard
- Merge
M
sorted lists each containingN
elementsHard - Merge
M
sorted lists of variable lengthHard - Huffman Coding Compression AlgorithmHard
- External Merge Sort AlgorithmHard
Graphs:
- Graph Implementation in C++ using STLBeginner
- Breadth-First Search (BFS) – Iterative and Recursive ImplementationMedium
- Depth First Search (DFS) – Iterative and Recursive ImplementationMedium
- Disjoint–Set Data Structure (Union–Find Algorithm)Medium
- Kruskal’s Algorithm for finding Minimum Spanning TreeHard
- Single-Source Shortest Paths – Dijkstra’s AlgorithmMedium
- Graph Coloring ProblemMedium
- Print all Hamiltonian paths present in a graphHard
- Kahn’s Topological Sort AlgorithmMedium
- Compute the least cost path in a weighted digraph using BFSMedium
Array:
- Rearrange an array with alternate high and low elementsMedium
- Find a pair with the given sum in an arrayEasy
- Find equilibrium index of an arrayEasy
- Find majority element (Boyer–Moore Majority Vote Algorithm)Easy
- Print all subarrays with 0 sumMedium
- Find maximum length subarray having a given sumMedium
- Find maximum length subarray having an equal number of 0’s and 1’sMedium
- Find all distinct combinations of a given length – IMedium
- Find all distinct combinations of a given length – IIMedium
- Find all distinct combinations of a given length with repetition allowedMedium
- Merging Overlapping IntervalsMedium
- Find minimum platforms needed to avoid delay in the train arrivalMedium
- Longest Increasing Subsequence ProblemHard
- Iterative Implementation of QuicksortMedium
- Sort elements by their frequency and indexMedium
- Sort an array based on order defined by another arrayMedium
- Find a triplet with the given sum in an arrayMedium
- 4–Sum Problem | Quadruplets with a given sumMedium
- Binary Search Algorithm – Iterative and Recursive ImplementationEasy
- Find the peak element in an arrayMedium
- Activity Selection ProblemEasy
- Job Sequencing Problem with DeadlinesMedium
- Maximum Product Subset ProblemEasy
- Find pairs with difference
k
in an array | Constant Space SolutionMedium - Find pairs with difference
k
in an arrayEasy - Quickselect AlgorithmMedium
- Check if a subarray with 0 sum exists or notMedium
- 4–Sum Problem | Quadruplets with a given sumMedium
- Print all distinct subsets of a given setHard
- K–Partition Problem | Printing all partitionsHard
- 3–Partition ProblemMedium
- 3–partition problem extended | Printing all partitionsHard
- Find the frequency of each element in a sorted array containing duplicatesEasy
- Replace each array element by its corresponding rankEasy
- Group elements of an array based on their first occurrenceMedium
- Find all symmetric pairs in an array of pairsMedium
- Find the count of distinct elements in every subarray of size
k
Medium - Print all subarrays of an array having distinct elementsMedium
- Find ways to calculate a target from elements of the specified arrayMedium
- Find the minimum index of a repeating element in an arrayEasy
- Check if an array is formed by consecutive integersMedium
- Find two non-overlapping pairs having the same sum in an arrayMedium
- Find two numbers with maximum sum formed by array digitsEasy
- Count distinct absolute values in a sorted arrayMedium
- Find subarrays with a given sum in an arrayMedium
- Find surpasser count for each array elementHard
- Find the maximum absolute difference between the sum of two non-overlapping subarraysHard
- Print all combinations of numbers from 1 to
n
having sumn
Medium - Find an index of the maximum occurring element with equal probabilityEasy
Matrix:
- Find all occurrences of the given string in a character matrixHard
- Flood Fill AlgorithmMedium
- Count number of islandsMedium
- Find all paths from the first cell to the last cell of a matrixMedium
- Find the probability that a person is alive after taking
n
steps on an islandMedium - Find the path from source to destination in a matrix that satisfies given constraintsMedium
- Find all common elements present in each row of a matrixMedium
- Construct a binary tree from an ancestor matrixHard
- Find common elements present in all rows of a matrixMedium
- Find the shortest distance of every cell from a landmine inside a mazeHard
- Find duplicate rows in a binary matrixMedium
Strings:
- Check if a string is a rotated palindrome or notMedium
- Check if a repeated subsequence is present in a string or notHard
- Check if strings can be derived from each other by circularly rotating themEasy
- Determine whether two strings are anagram or notEasy
- Find all binary strings that can be formed from a wildcard patternMedium
- Find all interleaving of given stringsEasy
- Isomorphic StringsMedium
- Find all possible palindromic substrings of a stringHard
- Find all possible combinations of words formed from the mobile keypadHard
- Find all possible combinations by replacing given digits with characters of the corresponding listHard
- >Find all words that follow the same order of characters as given patternMedium
- Find first
k
non-repeating characters in a string in a single traversalMedium - Group anagrams together from a list of wordsMedium
- Reverse text without reversing individual wordsMedium
- Find the longest substring of a string containing
k
distinct charactersHard - Find all palindromic permutations of a stringMedium
- Find all substrings of a string that are a permutation of another stringMedium
- Find the longest substring of a string containing distinct charactersMedium
- Find all permutations of a string in C++ (Using Backtracking and STL)Hard
- Find all lexicographically next permutations of a string sorted in ascending orderHard
- Lexicographically Minimal String RotationMedium
- Find all n-digit binary numbers with k-bits set where
k
ranges from 1 ton
Hard - Generate binary numbers between 1 to
n
using a queueEasy - Lexicographic rank of a stringHard
- Shortest Superstring ProblemHard
- Check if a string is interleaving of two other given stringsMedium
- Iterative approach to finding permutations of a stringHard
- std::next_permutation | Overview and Implementation in C++Medium
- std::prev_permutation | Overview and Implementation in C++Medium
- Implementation of KMP AlgorithmHard
- Construct the longest palindrome by shuffling or deleting characters from a stringMedium
- Determine whether the characters of a string follow a specified order or notMedium
- Determine whether a string matches with a given patternHard
Binary Tree:
- Check if two binary trees are identical or notEasy
- Calculate the height of a binary treeEasy
- Delete a binary treeEasy
- Level order traversal of a binary treeEasy
- Spiral order traversal of a binary treeMedium
- Reverse level order traversal of a binary treeEasy
- Print all nodes of a perfect binary tree in a specific orderHard
- Print left view of a binary treeEasy
- Print bottom view of a binary treeMedium
- Print top view of a binary treeMedium
- Find the next node at the same level as the given node in a binary treeMedium
- Check if a binary tree is a complete binary tree or notMedium
- Determine whether a binary tree is a subtree of another binary treeMedium
- Postorder Tree TraversalMedium
- Preorder Tree TraversalMedium
- Inorder Tree TraversalMedium
- Find ancestors of a given node in a binary treeMedium
- Find the vertical sum of a binary treeHard
- Perform vertical traversal of a binary treeMedium
- Find the diagonal sum of a binary treeMedium
- Print diagonal traversal of a binary treeMedium
- Print corner nodes of every level in a binary treeEasy
- Print right view of a binary treeMedium
- Compute the maximum number of nodes at any level in a binary treeEasy
- Build a binary tree from a parent arrayHard
- Find a pair with the given sum in a BSTEasy
- Construct a binary tree from an ancestor matrixHard
- Iteratively print the leaf to root path for every leaf node in a binary treeMedium
Dynamic Programming:
- Introduction to Dynamic ProgrammingBeginner
- Longest Common Subsequence ProblemMedium
- Longest Common Subsequence | Finding all LCSHard
- Longest Common Subsequence of k–sequencesMedium
- Longest Palindromic Subsequence using Dynamic ProgrammingMedium
- Longest Repeated Subsequence ProblemMedium
- Shortest Common Supersequence ProblemMedium
- Find the longest sequence formed by adjacent numbers in the matrixMedium
- Count the number of paths in a matrix with a given cost to reach the destination cellMedium
- 0–1 Knapsack ProblemMedium
- Subset Sum Problem – Dynamic Programming SolutionMedium
- Minimum Sum Partition ProblemHard
- Coin Change ProblemHard
- Find optimal cost to construct a binary search treeHard
- Maximum Length Snake SequenceMedium
- Check if a string is interleaving of two other given stringsMedium
- Find ways to calculate a target from elements of the specified arrayMedium
Linked List:
- Detect cycle in a linked list (Floyd’s Cycle Detection Algorithm)Easy
- Remove duplicates from a linked list in a single traversalEasy
- Remove duplicates from a linked list in a single traversalEasy
- Convert a multilevel linked list to a singly linked listMedium
Miscellaneous:
- C++ Implementation of Trie Data StructureBeginner
- Memory Efficient Implementation of Trie in C++ – Insert, Search and DeleteBeginner
- Generate the power set of a given setMedium
- Find numbers represented as the sum of two cubes for two different pairsMedium
- Traverse a given directory using BFS and DFS in JavaEasy
Thanks for reading.
To share your code in the comments, please use our online compiler that supports C, C++, Java, Python, JavaScript, C#, PHP, and many more popular programming languages.
Like us? Refer us to your friends and support our growth. Happy coding :)