Skip to main content

All Questions

Filter by
Sorted by
Tagged with
9 votes
3 answers
2k views

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
4 votes
3 answers
291 views

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
1 vote
2 answers
691 views

Duplicate Binary Search Improvements

I'm working on an implementation of binary search (in Python) that can operate on a sorted array that may have duplicate elements. I've written a submission that has managed to hold up against my test ...
Stanley Yu's user avatar
1 vote
2 answers
110 views

Binary Search using recursive approach

Is the following implementation of recursive function correct? How about the time complexity of the code; is it good in terms of performance? ...
Siawash Kasra's user avatar
4 votes
1 answer
816 views

Compute the square root of a positive integer using binary search

The requirement is to find the square root of a positive integer using binary search and the math property that square root of a number n is between ...
nonopolarity's user avatar
4 votes
1 answer
1k views

Building balanced BST from sorted array: recursive and iterative approaches

I am implementing an algorithm to solve the following problem: Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal ...
desa's user avatar
  • 143
4 votes
1 answer
154 views

Generalisation of Binary Search

I wrote a function to implement a generalised version of binary search that can find the minimum or maximum index in a given sorted list that satisfies a provided predicate. My Code ...
Tobi Alafin's user avatar
  • 1,792
3 votes
1 answer
109 views

Extended Binary Search Function (python)

I wrote a function to find the closest value in a list to a given search value. What prompted me to write it was as boilerplate for a prime number problem so I could find the closest prime to a given ...
Tobi Alafin's user avatar
  • 1,792
3 votes
1 answer
1k views

Find the minimum path sum in a binary tree

I am working on the problem of finding the minimum path sum in a binary tree, and printing the path. The path can be from the root node to any leaf node. Here is my code in Python 2.7. I am looking ...
Lin Ma's user avatar
  • 3,543
5 votes
1 answer
843 views

Counting the number of elements in a sorted array

Suppose I have a sorted array, and each element may appear multiple times. To make it simple, here is an example: ...
Lin Ma's user avatar
  • 3,543
3 votes
1 answer
1k views

Minimize max distance of Gas Station

I'm working on this problem, and any advice on performance improvement, bugs or code style issues are appreciated. Problem Description There are N gas stations on a straight, M kilo-meters ...
Lin Ma's user avatar
  • 3,543
2 votes
1 answer
105 views

Find valid triples for a sorted list of integers (part 2)

Have some ideas to improve code from this discussion (Find valid triples for a sorted list of integers) and post new code in a new post. The new idea is to try to remember where low bound searched ...
Lin Ma's user avatar
  • 3,543
4 votes
1 answer
869 views

Find valid triples for a sorted list of integers

I'm working on a problem in which I have an input array, sorted positive unique integers, and have to try to find all possible triples \$(x,y,z)\$ which satisfy \$x+y>z\$ and \$x<y<z\$. For ...
Lin Ma's user avatar
  • 3,543
2 votes
2 answers
5k views

Using binary search to find the index of an item in a sequence

Here's my script: ...
Mahmood Muhammad Nageeb's user avatar
3 votes
2 answers
2k views

Calculate the path sum of a binary tree

I want to calculate all sum of all possible paths from root to leaf. Each node has value of an integer number (decimal). In the following example: ...
Lin Ma's user avatar
  • 3,543

15 30 50 per page