2dbi
Home/IBM/Sort Integers by the Power Value (Collatz)
IIBM·DSABand 7Online Assessment

Sort Integers by the Power Value (Collatz)

Problem

Sort integers in [lo, hi] by their Collatz-style 'power' (steps to reach 1), ties by value; return the k-th.

Example

lo=12, hi=15, k=2 -> 13

Constraints

  • 1 ≤ lo ≤ hi ≤ 1000

Approach

Compute power with memoization; sort by (power, value). Reported IBM OA question.

added 6 days ago
LeadersAccount