Algorithms

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 technical problem deals with finding a route between two nodes in a directed graph. An example input is given, as well as the desired output.
About this solution: The candidate's solution is correct and demonstrates a level of completeness. The candidate has correctly implemented a breadth-first search algorithm to find whether there is a route between two nodes in a directed graph.
Dec 11
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
This problem deals with determining if a given value is present in a sorted array. An example input is given as [1, 3, 5, 7], 5, with the expected output being true.
About this solution: The candidate's solution is correct and demonstrates a level of completeness. The candidate has correctly identified that the optimal solution is to use a binary search algorithm, and has correctly implemented a recursive binary search algorithm. The candidate's solution correctly returns true when the value is found in the array, and correctly returns false when the value is not found in the array.
Dec 11
Code Problem / Data Structures and Algorithms DifficultyMedium Python
Given an array of n integers, find the contiguous subarray of given length k that has the maximum average value. Output the maximum average value.
About this solution: The candidate's solution correctly finds the maximum average value of a given array and length k. The solution is clear and easy to follow. One potential improvement would be to use the built-in max() and sum() functions rather than creating a custom max_sum function.
Dec 11
Code Problem / Data Structures and Algorithms DifficultyMedium C++
This problem asks us to find all possible subsets of a given set of distinct integers. A subset is simply a subset of elements from the given set, and the power set is the set of all possible subsets. Note that the solution set must not contain duplicate subsets.
About this solution: The candidate's solution is complete and solves the problem. The approach is to first add the empty subset to the result, and then iterate through the nums array, adding each element to all of the existing subsets to create new subsets.
Dec 11
Code Problem / Data Structures and Algorithms DifficultyMedium C++
Given a list of positive integers, this algorithm finds the two integers that have the largest product.
About this solution: The candidate's solution is optimal because it only iterates through the vector once. However, the candidate does not provide a detailed explanation of their approach, which makes it difficult to understand their thought process. In addition, the candidate does not comment on their code, which makes it difficult to follow.
Dec 11
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
Given a stack of integers, the function returns the sum of the elements in the stack.
About this solution: The candidate's solution is correct and solves the problem. The approach is straightforward and easy to understand. The time complexity of the solution is O(n) and the space complexity is O(1).
Dec 11
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 C++
Given a string, this function finds the first non-repeating character in it.
About this solution: The candidate's solution correctly finds the first non-repeating character in a string. The solution uses a hash map to keep track of the number of times each character appears in the string, then loops through the string again to find the first character with a count of 1. One potential improvement to this solution would be to use a LinkedHashMap instead of a regular hash map, so that the order in which the characters are added to the map is preserved. This would allow the solution to find the first non-repeating character in the string in a single loop, without having to loop through the string twice.
Dec 10