Skip to content
Onsite

Smallest X for Quadratic at Least K

MediumP3Coding

Given non-negative integers a, b, c and k, find the smallest non-negative integer x such that a * x^2 + b * x + c >= k. If no such x exists, return -1.

Example 1

Input
a = 1, b = 0, c = 0, k = 10
Output
4
Why
4^2 = 16 >= 10 and 3^2 = 9 < 10.

Example 2

Input
a = 0, b = 0, c = 5, k = 6
Output
-1
Why
The value is always 5.

Example 3

Input
a = 2, b = 3, c = 10, k = 5
Output
0
Why
At x = 0 the value is already 10.

Constraints

  • 0 <= a, b, c <= 10^5
  • 0 <= k <= 10^9

Hints

Run checks the 3 visible tests, Submit all 12.