Skip to content
We areTOP 1%

Sum of Cubes

EasyRating 1100CodeforcesBinary Search
Solve on Codeforces(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

Since x is at most 10^12, the smaller cube root is at most 10^4. Fix a, then binary search for an integer b with b^3 = x - a^3; avoid floating-point cbrt, which can be off by one.

More in Binary Search

Binary Search questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Binary SearchLeetCodeEasy Solve Binary Search on LeetCode (opens in a new tab)
2Search Insert PositionLeetCodeEasy Solve Search Insert Position on LeetCode (opens in a new tab)
3First Bad VersionLeetCodeEasy Solve First Bad Version on LeetCode (opens in a new tab)
4LettersCodeforcesEasy 1000Solve Letters on Codeforces (opens in a new tab)
5Interesting drinkCodeforcesEasy 1100Solve Interesting drink on Codeforces (opens in a new tab)
6Eating QueriesCodeforcesEasy 1100Solve Eating Queries on Codeforces (opens in a new tab)
7Sum of CubesCodeforcesEasy 1100Solve Sum of Cubes on Codeforces (opens in a new tab)
8WormsCodeforcesEasy 1200Solve Worms on Codeforces (opens in a new tab)
9Find First and Last Position of Element in Sorted ArrayLeetCodeMedium Solve Find First and Last Position of Element in Sorted Array on LeetCode (opens in a new tab)
10Find Minimum in Rotated Sorted ArrayLeetCodeMedium Solve Find Minimum in Rotated Sorted Array on LeetCode (opens in a new tab)
11Search in Rotated Sorted ArrayLeetCodeMedium Solve Search in Rotated Sorted Array on LeetCode (opens in a new tab)
12Find Peak ElementLeetCodeMedium Solve Find Peak Element on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account