Binary Search

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 Python
The function should take a sorted array of integers and a target value as inputs, and return the index of the target value if it exists in the array, or -1 if it does not .
About this solution: This is a well-detailed and complete solution to the problem. The candidate has correctly identified the time and space complexity of the solution and has provided a clear explanation of the approach. The candidate has also correctly implemented a binary search algorithm to solve the problem.
Nov 28
Code Problem / Data Structures and Algorithms DifficultyMedium Python
The binary search algorithm returns the index of the target value if it exists in the array, or -1 if it does not.
About this solution: The candidate's solution is a binary search, which is the optimal solution for this problem. The time complexity of a binary search is O(log n), which is better than the time complexity of a linear search, which is O(n). The candidate's solution correctly returns the index of the target value if it exists in the array, or -1 if it does not.
Nov 27
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
This problem deals with implementing a binary search algorithm to find a target value in a list of integers. If the target value is present in the list, the function should return its index; if not, the function should return -1.
About this solution: This is a good solution that demonstrates a level of completeness and solves the problem. The approach is straightforward and easy to understand. The only improvement that could be made is to add some comments to explain the logic behind the solution.
Nov 26
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
This function will take a list of integers and a key as input, and will return the index of the key if it exists in the list, or -1 if it does not exist.
About this solution: This is a good solution that correctly implements a linear search through the array.
Nov 25
Code Problem / Data Structures and Algorithms DifficultyMedium C++
The "Binary Search" code problem asks the user to write a function that takes a sorted array of integers and a target value as input, and returns the index of the target value if it is present in the array. If the target value is not present in the array, the function should return -1.
About this solution: The candidate's solution correctly implements a binary search algorithm to find the index of a given target value in a sorted array. The solution is complete and correctly handles the case where the target value is not present in the array.
Nov 25
Code Problem / Data Structures and Algorithms DifficultyMedium C++
The problem is to find the index of a given target value in a sorted array of integers, or return -1 if the target value is not present in the array.
About this solution: The candidate's solution is a complete and working solution to the problem. The candidate has used a binary search algorithm, which is an efficient way to search for a value in a sorted array.
Nov 24
Code Problem / Data Structures and Algorithms DifficultyMedium C++
Given a sorted array and a target value, this problem asks to find the index of the first element in the array that is greater than the target. For example, given the array [1 , 2, 3, 4, 5] and target value 3, the output would be 2 since 2 is the index of the first element in the array (4) that is greater than the target value.
About this solution: The candidate's solution is complete and solves the problem. The candidate has used a binary search algorithm which is a good approach.
Nov 23
Code Problem / Data Structures and Algorithms DifficultyMedium C++
This problem asks the reader to determine whether a target value exists in a sorted array of integers. An example input and output are given.
About this solution: The candidate's solution correctly implements a binary search algorithm to solve the problem. The code is well organized and easy to read. The candidate demonstrates a good understanding of the algorithm and its implementation.
Nov 22