Data Structures & AlgorithmsVery hardTCS NQT · Infosys
Starting at n = 7, repeat: if n is even replace n by n/2, otherwise replace n by 3n + 1. How many steps are needed to reach 1?
- A. 16
- B. 17
- C. 18
- D. 20
Correct answer: A. 16
The sequence is 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, and counting its transitions gives 16. Counting the terms instead gives 17.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the total number of comparisons made by insertion sort on the array [3, 1, 4, 1, 5] (each test of a[j-1] > a[j] counts as one…
- An array has values [1, 1, 1, 2, 2, 3, 4, 4, 4, 4, 5]. Every value that occurs more than twice is removed entirely. How many elements…
- How many index pairs i < j in the sorted array [1, 2, 4, 6, 7, 9] satisfy a[i] + a[j] <= 10?
- What is the value of 7^100 mod 9?
- How many integers x in [1, 100] satisfy that x^2 + x + 41 is divisible by 43?
- Matrices A1 to A6 have dimension sequence p = [30, 35, 15, 5, 10, 20, 25] (matrix i is p[i−1] × p[i]). What is the minimum number of…