Code Problem / Data Structures and Algorithms / Backtracking

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#
This problem asks us to return all possible subsets of a given set of distinct integers. For example, if the input is [1,2,3], then the output should be all possible subsets of those integers: [1], [1,2], [1,2,3], [1,3], [2], [2,3], and [3].
About this solution: The candidate's solution is complete and solves the problem. The approach is to generate all subsets by iterating through the input array and adding each element to all existing subsets.
Dec 12
Code Problem / Data Structures and Algorithms DifficultyMedium Python
This problem asks you to write a function that returns all possible permutations of a given string. For example, given the input string "abc", the function should return the following six permutations : "abc", "acb", "bac", "bca", "cab", and "cba".
About this solution: This solution is complete and solves the problem. The approach is to generate all permutations by looping through the characters in the string and then recursively generating all permutations of the remaining characters.
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 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
Given a set of distinct integers, this algorithm returns all possible subsets. The subsets must be in non-descending order, and the solution set must not contain duplicate subsets.
About this solution: The candidate's solution is correct and solves the problem. The approach is to first sort the given set, then create all possible subsets by iterating through the set and adding each element to all existing subsets.
Dec 07
Code Problem / Data Structures and Algorithms DifficultyMedium Python
Given a set of distinct integers, this algorithm will return all possible subsets. For example, if the input is [1,2,3], the output will be [[],[1],[ 2],[3],[1,2],[1,3],[2,3],[1,2,3]].
About this solution: This is a great solution! It is complete, and correctly solves the problem. The approach is also very elegant.
Dec 07
Code Problem / Data Structures and Algorithms DifficultyMedium Python
This problem asks for all possible permutations of a set of distinct integers.
About this solution: This solution is complete and solves the problem. The approach is to generate all permutations by iterating through the list of numbers and recursively generating all permutations of the remaining numbers.
Dec 06
Code Problem / Data Structures and Algorithms DifficultyMedium C++
Given a 2D array of integers, write a function that returns the length of the longest path of consecutive integers starting from the top left corner of the array. The path can move up, down, left, or right.
About this solution: The candidate's solution is complete and solves the problem. The candidate has taken a dynamic programming approach, which is a good approach for this problem. The candidate's code is well-written and easy to understand.
Dec 05