DEV Community

Subroutines: Interview Problem Survey

The text discusses various algorithms and their applications in solving different problems. It starts with a palindrome check algorithm that can be used as a subroutine in various problems. The algorithm checks if a string is a palindrome by comparing characters from the start and end of the string. To make the algorithm more versatile, additional parameters can be added to handle cases where at most one character can be deleted. This is demonstrated with a solution to LeetCode problem 680. The text then shifts to depth-first search (DFS) and breadth-first search (BFS) algorithms, which are commonly used in interview problems. An example of a DFS problem is finding the number of islands or the largest island in a matrix where '1' denotes land and '0' denotes water. The solution involves using DFS to traverse the matrix and count the number of islands or the size of the largest island. Another example of a DFS problem is finding all expressions that evaluate to a target number by introducing binary operators into a string of numbers. This is demonstrated with a solution to LeetCode problem 282. The solution involves using DFS to generate all possible expressions and checking if they evaluate to the target number. The algorithm uses recursion to explore all possible expressions and backtracking to prune branches that do not lead to a solution.
favicon
dev.to
dev.to