The Peak of Chaos
HardAcc. 79.1%
+45 XP 25
Searching for Complexity
In this mission, you must find which number between 1 and a given limit creates the longest sequence before hitting 1.
The Assignment
Your function receives a parameter limit.
- Initialize
maxSteps = 0andbestNum = 0. - Outer loop from 1 to
limit. - Inner loop to calculate Collatz steps for each number.
- Keep track of the number with the most steps.
- Print: "target produced steps steps" (e.g., "9 produced 19 steps").
01EXAMPLE 1
Input
limit = 10Output
9 produced 19 stepsExplanation: 9 takes 19 steps to reach 1.
Constraints
- Double-nested loops (Outer: range, Inner: path).
- Handle limit=1 correctly.
MathLoops
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
limit10
Expected Output
9 produced 19 steps
Click RUN to test your solution