Medium · Sorting
Sort Integers by The Power Value
Given integers 1 ≤ lo ≤ hi ≤ 1000 and 1 ≤ k ≤ hi − lo + 1, where the power of x is the number of steps to reach 1 by replacing x with x / 2 when x is even and with 3x + 1 when x is odd, sort the integers in [lo, hi] by power ascending (ties by the smaller value) and return the k-th one (1-based).
Examples
Example 1
lo=12, hi=15, k=2Output: k-th = 13
Example 2
lo=7, hi=11, k=4Output: k-th = 7
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.