## Code Problem / Data Structures and Algorithms / Recursion

#### Recent solutions:

Check these solutions from our community:
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
Given an array of integers, write a function that returns the sum of all the odd numbers in the array.
About this solution: This is a great solution! It is very efficient because it only iterates through the array once and only adds the odd numbers to the sum.
Nov 22
Code Problem / Data Structures and Algorithms DifficultyMedium Python
This problem deals with finding a subset of distinct integers that sum to a given number. An example input and output are given.
About this solution: The candidate's solution is complete and solves the problem. The candidate uses a dynamic programming approach, which is a good approach for this problem.
Nov 21
Code Problem / Data Structures and Algorithms DifficultyMedium Python
Given a binary tree, this function determines whether the tree is balanced. A balanced binary tree is one in which the left and right subtrees of each node have heights that differ by no more than 1. This example input results in an output of True.
About this solution: The candidate's solution correctly determines whether the given tree is balanced. The approach is to recursively check the left and right subtrees of each node to see if their heights differ by no more than 1. This is a correct approach.
Nov 21
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
Given a set of distinct integers, this program prints out the power set of the set. The power set of a set is the set of all its subsets.
About this solution: The candidate's solution is a good start, but it is not complete. The solution does not actually print the power set, it only returns it. To print the power set, the candidate would need to add a line to print the array at the end of the function. Additionally, the candidate's solution only works for sets with distinct integers. To make the solution work for sets with non-distinct integers, the candidate would need to add additional logic to check for duplicates.
Nov 20
Code Problem / Data Structures and Algorithms DifficultyMedium C++
This problem asks you to find the maximum path sum in a binary tree. A path is defined as any sequence of nodes from some starting node to any node in the tree along the parent- child connections. The path must contain at least one node and does not need to go through the root.
About this solution: The candidate's solution correctly solves the problem. The approach is to recursively find the maximum path sum for each node in the tree. The path sum for each node is the node's value plus the maximum of the path sums for the node's left and right child nodes. The maximum path sum for the tree is the maximum of the path sums for all nodes in the tree.
Nov 19
Code Problem / Data Structures and Algorithms DifficultyMedium Python
The problem asks us to print the power set of a given set of distinct integers. A power set is the set of all subsets of a given set, including the empty set and the original set itself. For example, the power set of {1,2,3} would be {{},{1},{2},{3},{1,2},{1,3 },{2,3},{1,2,3}}.
About this solution: This is a good solution that demonstrates a level of completeness and solves the problem. The approach is recursive and uses a set and a list to keep track of the elements in the power set.
Nov 12
Code Problem / Data Structures and Algorithms DifficultyMedium Python
This problem asks you to find the sum of all the elements in an array, using recursion. That is, you need to define a function that takes in an array of integers, and returns the sum of all the integers in the array. For example, given the input [1, 2, 3, 4], your function should return 10.
About this solution: This solution is complete and solves the problem. The approach is straightforward and easy to follow.
Nov 07
Code Problem / Data Structures and Algorithms DifficultyMedium Python
Given a binary tree and a value, return the sum of all values in the tree that are greater than or equal to the given value.
About this solution: The candidate's solution is complete and solves the problem. The approach is to recursively traverse the tree, keeping track of the sum of values that are greater than or equal to the given value. This is a good approach and is implemented correctly.
Nov 07