Medium · Sorting

Sort Integers by The Power Value

Given integers lo, hi and k, 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=2

Output: k-th = 13

Example 2

lo=7, hi=11, k=4

Output: k-th = 7

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Sorting problems