Skip to main content

Questions tagged [binary-search]

Use this tag for code that implements a binary search.

7votes
4answers
1kviews

LeetCode 977: Squares of a sorted array, maintaining non-decreasing order

I tried solving the LeetCode question like many others, trying to incorporate the O(n) time complexity requirement. Squares of a Sorted Array Given an integer array ...
Littlejacob2603's user avatar
3votes
3answers
173views

Creating a search function

Write an efficient function in the Python language called SmartSearch. This function will receive a sorted arr array of integers of size \$n\$ containing at the ...
SHOVAL's user avatar
5votes
1answer
197views

Testing binary search module, based on bisect

The bisect module can only find the index to insert an element. I created a simple class based on the bisect module for precise searching and covered all the edge cases that came to mind with tests. ...
Aycon's user avatar
3votes
1answer
137views

Incremental upper bound in sorted range

Since initial question Increasing binary search for mismatch in sorted range contained defects in code and can confuse the readers, here is the updated version of the question. Is the code below ...
Damir Tenishev's user avatar
3votes
2answers
216views

Counting duplicate elements in two sorted arrays

I've been working on an assignment that involves optimizing a duplicate finding algorithm for sorted arrays, and I'd like to get your thoughts on the implementation. Here's the code I've come up with: ...
Bryan C's user avatar
4votes
1answer
318views

K&R exercise 3-1

...
Hansoko's user avatar
9votes
3answers
2kviews

Optimizing the Egg Drop Problem implemented with Python

I've implemented the Egg Drop Problem using Python. As described in the code, I'm trying to find the highest floor of a 102-story building from which I could drop an egg without it breaking. The ...
Muhammed Abiola's user avatar
4votes
3answers
1kviews

C++ Binary Search

Could you advise on this binary search implementation? ...
acd's user avatar
  • 107
-2votes
2answers
146views

Lower-Bound algorithm getting Time Limit Exceeded

...
Shakhawat Hossain SHIHAB's user avatar
1vote
1answer
119views

Binary search of 2D matrix

I have written code as below: ...
Szyszka947's user avatar
1vote
0answers
114views

USACO Silver "Wormhole Sort" solver

I'm struggling a bit with a USACO silver question using python, http://usaco.org/index.php?page=viewproblem2&cpid=992. The question provides an unsorted list of numbers (cows) and a number of ...
Luke's user avatar
3votes
1answer
2kviews

Find closest value in a big list

There are solutions e.g. list.OrderBy(item => Math.Abs(number - item)).First() or ...
nop's user avatar
  • 809
3votes
2answers
401views

Implementation of a market that matches bids to offers

This is my task: Each line in the file can be one of the following: Updates to the limit order book in the following format: ...
Данил Денк's user avatar
3votes
2answers
1kviews

Non recursive binary search in C

I wrote a non recursive binary search implementation in C, for this time I think there are no bugs. Here's the code: ...
manungsa's user avatar
4votes
3answers
283views

Increase efficiency of stick cutting algorithm

I have this typical code interview type problem. Suppose you have a stick of length n. You make X cuts in the stick at places x1, x2, x3 and so on. For every cut in X cuts you need to print the length ...
Some nerd who does not have a 's user avatar

153050per page
close