Skip to the code
cf.
+10 XP

#640 Zoom Level Power

easy

A map widget zooms by a fixed scale per step: zooming in steps times multiplies the size by scale that many times, and a negative steps means zooming out, which divides instead.

Write zoomPower(scale, steps) that returns scale to the power steps. steps can be very large, so use about log |steps| multiplications instead of |steps|. Answers within 1e-5 (relative) are accepted.

Example 1

Input: scale = 2, steps = 10
Output: 1024

2^10 = 1024.

Example 2

Input: scale = 2, steps = -2
Output: 0.25

A negative power divides: 1 / 2^2 = 0.25.

Constraints

  • -100 <= scale <= 100, scale !== 0
  • -2^31 <= steps <= 2^31 - 1
  • The answer is between -10^4 and 10^4, and at least 10^-4 in size when it isn't 0.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).