Where n² overtakes a line
Standard · Write code · about 8 min
A line costs a·n + b steps and a curve costs n². Return the smallest n ≥ 1 where n² is strictly bigger than the line.
Example 1
Input:
[3,5]
Output:
5
At n = 5: 25 beats 20. At n = 4: 16 does not beat 17.
Example 2
Input:
[0,0]
Output:
1
Constraints
- 0 ≤ a ≤ 1,000,000
- 0 ≤ b ≤ 1,000,000
Learn the idea first: Big-O, Big-Θ and Big-Ω, a visual lesson.
More Big-O, Big-Θ and Big-Ω problems
- Count the steps of a triangle loop Standard
- Guess the growth from a doubling test Standard