Code Problem

Categories: Code Problem / Data Structures and Algorithms / Recursion (32) Code Problem / Data Structures and Algorithms / Binary Search (30) Code Problem / Data Structures and Algorithms / Linked Lists (26) Code Problem / Data Structures and Algorithms / Backtracking (26) Code Problem / Data Structures and Algorithms / Stacks and Queues (25) Code Problem / Data Structures and Algorithms / Hashing (24) Databases / SQL / Backup and Recovery (19) Code Problem / Data Structures and Algorithms / Arrays and Strings (19) Databases / SQL / Database Normalization (18) Code Problem / Data Structures and Algorithms / Time Complexity (17) Databases / SQL / Locking (16) Databases / SQL / Replication (15) Databases / SQL / SQL Queries (13) Code Problem / Data Structures and Algorithms / Graphs (13) Databases / SQL / Database Security (13)  More...

Recent solutions:

Check these solutions from our community:
Code Problem / Data Structures and Algorithms DifficultyMedium C#
Given an array of integers, this problem seeks to find the length of the longest increasing subsequence within that array. For example, given the input array [10, 9, 2, 5 , 3, 7, 101, 18], the longest increasing subsequence would be of length 4.
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.
Dec 10
Code Problem / Data Structures and Algorithms DifficultyMedium Python
Given a 2D array of integers, this algorithm finds the length of the longest path of consecutive numbers that can be formed in the array. The path can start and end at any position in the array.
About this solution: The candidate's solution correctly uses a DFS algorithm to find the longest path in the array. The algorithm is optimal because it only needs to traverse the array once. However, there are a few errors in the implementation of the DFS function. First, the base case should check if the current element is out of bounds or if the current element is already visited. Second, the path variable should be initialized to 1 before the recursive call. Third, the DFS function should return the path variable after the recursive call. Fourth, the visited array should be reset after the DFS call.
Dec 10
Code Problem / Data Structures and Algorithms DifficultyMedium C#
This function takes in a string consisting only of parentheses and outputs whether or not the string is balanced. A string is balanced if every open parenthesis has a corresponding close parenthesis and there are no unmatched parentheses.
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.
Dec 10
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
Given an array of integers and a target value, return the indices of the two array elements that add up to the target value. Assume that each input will have only one solution, and that the same array element cannot be used twice.
About this solution: The candidate's solution is correct and demonstrates a level of completeness. The candidate's approach is also correct, using a hash table to store the numbers and their indices. This solution is optimal because it is O(n) time complexity and O(n) space complexity.
Dec 10
Code Problem / Data Structures and Algorithms DifficultyMedium Python
Given a set of distinct integers, this algorithm will return all possible subsets of those integers.
About this solution: The candidate's solution is a recursive function that takes in the input array and the current subset. The function iterates through the input array and adds each element to the current subset. It then calls itself with the input array and the new subset. The function also calls itself with the input array and the current subset. This allows the function to create all possible subsets. The function returns a list of all possible subsets. The function also adds the empty set to the list of subsets. The solution is correct and solves the problem. The approach is good, but could be more concise. For example, the helper function could be written as: def helper(nums, subset): subsets = [] for i in range(len(nums)): new_subset = subset + [nums[i]] subsets.append(new_subset) subsets += helper(nums[i+1:], new_subset) return subsets
Dec 10
Code Problem / Data Structures and Algorithms DifficultyMedium Python
This problem asks the programmer to return the sum of all integers at even indices in a given list. For example, given the list [1, 2, 3, 4, 5], the output would be 6 (2 + 4).
About this solution: This solution is correct and efficient. The candidate has demonstrated a good understanding of how to use the slice operator to get every other element in a list.
Dec 09
Code Problem / Data Structures and Algorithms DifficultyMedium C#
Given an array of integers, this code problem finds the sum of all elements in the array. The input is an array of numbers and the output is the sum of all the numbers in the array.
About this solution: The candidate's solution does not demonstrate a level of completeness and does not solve the problem. The candidate's approach is to simply print out the array elements without summing them.
Dec 09
Code Problem / Data Structures and Algorithms DifficultyMedium C++
This function takes in a set of integers and a target value, and returns true if there is a pair of integers in the set that sum up to the target value. Otherwise, it returns false.
About this solution: The candidate's solution is complete and solves the problem. The approach is to use a hash map to store the complement of each number in the array. If the complement exists in the hash map, then a pair exists that sums up to the target value.
Dec 09