Data Structures & AlgorithmsHardGATE CS · TCS NQT
Starting from n = 100, repeat: if n is divisible by 3, divide it by 3; otherwise subtract 1. How many steps are needed to reach 1?
- A. 8
- B. 9
- C. 11
- D. 7
Correct answer: D. 7
Count each operation. The path is 100, 99, 33, 11, 10, 9, 3, 1, which takes 7 operations.
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
- Which structure finds the k-th largest element of a data stream after each insertion with O(log k) time per element and O(k) space?
- Which method checks in O(n) whether two strings are isomorphic (a one-to-one character mapping turns one into the other)?
- Which technique counts the inversions of an array of n distinct integers in O(n log n) time?
- How many contiguous subarrays of [2, 4, 6, 3, 9] have an odd sum?
- What is the length of the longest proper border of the string aabaaab (the longest proper prefix that is also a suffix)?
- Which algorithm finds all occurrences of a pattern in a text in expected linear time using a rolling hash of each window?