Back to problems

Pow(x, n)

Algorithm · Meta · Medium

Requirements Create the function below so it returns \(x^n\), including when n is negative. The running time must be O(log n ), using repeated squaring either iteratively or recursively. Account for the boundary case n = INT_MIN. Negating that value directly can overflow, so convert it to a wider integer type or treat the case separately. Constraints n may be positive, zero, or negative. n is a signed 32-bit integer, so INT_MIN is a possible input. x is a numeric value for…

Checking your access…