Collatz Steps

JavaScript Medium 2 views
Back to Questions

Problem Description

Given n, apply Collatz until it becomes 1. If n is even: n=n/2 else n=3n+1. Print number of steps. If steps cross 1000000, print -1.

Input Format

One integer n.

Output Format

One integer steps.

Sample Test Case

Input:
6
Output:
8

Constraints

1

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next