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.

  1. Initialize maxSteps = 0 and bestNum = 0.
  2. Outer loop from 1 to limit.
  3. Inner loop to calculate Collatz steps for each number.
  4. Keep track of the number with the most steps.
  5. Print: "target produced steps steps" (e.g., "9 produced 19 steps").

01EXAMPLE 1

Inputlimit = 10
Output9 produced 19 steps

Explanation: 9 takes 19 steps to reach 1.

Constraints

  • Double-nested loops (Outer: range, Inner: path).
  • Handle limit=1 correctly.
MathLoops
JavaScript
Loading...
2 Hidden

Input Arguments

limit10

Expected Output

9 produced 19 steps

Click RUN to test your solution