ORIGINAL CODING QUESTION
Largest cube of storage boxes
A warehouse planner wants to stack unit boxes into the largest solid cube possible using at most x boxes. Return the largest integer side length r ≥ 0 with r * r * r ≤ x. Solve it with integer arithmetic rather than a floating-point cube-root function.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
One nonnegative integer x. Print r.
Constraints
0 ≤ x ≤ 1,000,000,000,000.
Example 1
Input
30
Output
3
3 * 3 * 3 = 27 fits, but 4 * 4 * 4 = 64 does not.
Example 2
Input
64
Output
4
A perfect cube returns its exact side, 4.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
If side r fits, every smaller side also fits, so the answer is a boundary.
Hint 2
Search r in [0, 10001]; 10001 cubed already exceeds the largest x.
Hint 3
Keep lo as a side that fits and hi as one that does not; compare mid * mid * mid with x until they are adjacent.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →