## Code Problem / Data Structures and Algorithms / Recursion

#### Recent solutions:

Check these solutions from our community:
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
This technical problem deals with how to print all possible permutations of a given string using recursion. For example, if the input string is "abc", the output would be all six possible permutations of the string: "abc", "acb", "bac", "bca", "cab", and "cba".
About this solution: This is a good solution that uses recursion to generate all permutations of a given string. The time complexity of this solution is O(n!), which is optimal.
Dec 05
Code Problem / Data Structures and Algorithms DifficultyMedium Python
Given a binary tree, this function checks whether it is symmetrical around its center. For example, the first tree in the input is symmetrical, but the second one is not.
About this solution: The candidate's solution correctly implements a recursive solution to check if a binary tree is symmetric. The approach is sound, and the code is clean and easy to follow.
Dec 03
Code Problem / Data Structures and Algorithms DifficultyMedium C++
This technical problem involves finding the sum of all elements in an array. The input is an array of integers, and the output is the sum of all elements in the array.
About this solution: The candidate's solution is correct and demonstrates an understanding of how to find the sum of all elements in an array. The candidate's approach is clear and concise.
Nov 30
Code Problem / Data Structures and Algorithms DifficultyMedium C#
To find the maximum depth of a binary tree, we can use recursion. First, we need to check if the tree is empty. If not, we need to find the maximum depth of the left and right subtrees. The maximum depth of the tree is the maximum of the left and right subtrees' depths, plus one.
About this solution: The candidate's solution correctly finds the maximum depth of a binary tree. The solution uses a recursive approach, which is a good approach for this problem. The solution is clear and easy to understand.
Nov 30
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
This technical problem deals with finding the sum of all integers in a list using recursion. An example input is given, along with the expected output.
About this solution: This solution is correct and demonstrates a good understanding of recursion. The approach is clear and concise.
Nov 30
Code Problem / Data Structures and Algorithms DifficultyMedium C#
The greatest common divisor of two positive integers can be found by recursively dividing the larger number by the smaller number until the remainder is 0.
About this solution: The candidate's solution does not demonstrate a level of completeness and does not solve the problem. The general approach is not clear.
Nov 30
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
This technical problem deals with returning all possible subsets of a given set of distinct integers. For example, if the input is [1,2,3], the output should be all possible subsets of those integers, which are [], [1], [2], [3], [1,2], [1,3], [2,3], and [1,2, 3].
About this solution: This is a good solution. It is recursive and correctly implements the algorithm. It is also optimal in terms of time and space complexity.
Nov 29
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
This problem asks you to write a function to reverse a singly linked list in place. The input is a singly linked list, and the output should be the same list, but reversed .
About this solution: The candidate's solution is a good attempt at solving the problem. However, there are a few things that could be improved. First, the candidate does not mention what the input and output of the function are. It is assumed that the input is a singly linked list and the output is the reversed singly linked list. Second, the candidate does not mention any edge cases that need to be considered. For example, what if the linked list is empty? What if the linked list has only one node? Third, the candidate's explanation of the while loop could be more clear. In particular, it is not entirely clear what is happening when the current node is set to the next node. Overall, the candidate's solution is a good attempt at solving the problem. With some clarification, it could be a great solution.
Nov 28