Tap here to switch tabs
Problem
Submissions

Problem: Sort Integers by The Power Value

Sort Integers by The Power Value orders an inclusive range by steps to reach one. Halve even values and turn odd values into three times the value plus one. Return the k-th, breaking ties by number.

Statement

The power of an integer xx is defined as the number of steps required to transform xx into 11 by repeatedly applying the following operations:

  • If xx is even, then x=x/2x = x / 2

  • If xx is odd, then x=3×x+1x = 3 \times x + 1

Given three integers lo, hi, and k, sort all integers in the inclusive range [[lo, hi]] in ascending order based on their power value. If two or more integers have identical power values, sort them in ascending numerical order.

Return the kk-th integer (11 indexed) in the sorted range.

Constraints:

  • 1≤1 \leq lo ≤\leq hi ≤1000\leq 1000

  • 1≤1 \leq k ≤\leq hi −- lo +1+ 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sort Integers by The Power Value

Sort Integers by The Power Value orders an inclusive range by steps to reach one. Halve even values and turn odd values into three times the value plus one. Return the k-th, breaking ties by number.

Statement

The power of an integer xx is defined as the number of steps required to transform xx into 11 by repeatedly applying the following operations:

  • If xx is even, then x=x/2x = x / 2

  • If xx is odd, then x=3×x+1x = 3 \times x + 1

Given three integers lo, hi, and k, sort all integers in the inclusive range [[lo, hi]] in ascending order based on their power value. If two or more integers have identical power values, sort them in ascending numerical order.

Return the kk-th integer (11 indexed) in the sorted range.

Constraints:

  • 1≤1 \leq lo ≤\leq hi ≤1000\leq 1000

  • 1≤1 \leq k ≤\leq hi −- lo +1+ 1