All problems
Integer Cube Root
Problem
Return the integer cube root of a non-negative integer n: the largest integer x with x * x * x <= n.
Binary search the answer between 0 and an upper bound found by doubling, comparing mid cubed with n. Always return the floor value.
Hint
Doubling the upper bound first keeps the binary search range small.
Test cases
case 1
in: [27]
expected: 3
case 2
in: [26]
expected: 2
case 3
in: [0]
expected: 0
case 4
in: [1]
expected: 1
case 5
in: [1000]
expected: 10
case 6
in: [2]
expected: 1
Starter codePython
def integer_cube_root(n):
# Your code here
pass6 test cases · run your code against them in the editor