Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A robot on a circle of 8 positions (0 to 7) starts at 0 and jumps 3 positions forward each step, wrapping around. After how many steps does it first return to position 0?
- A. 8
- B. 9
- C. 10
- D. 12
Correct answer: A. 8
Since gcd(3, 8) = 1, the jumps visit every position before returning, so the robot returns after 8 steps.
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
- Trains arrive at times [900, 940, 950, 1100] and depart at times [910, 1200, 1120, 1130]. What is the minimum number of platforms needed…
- What is the most efficient general technique for the platform problem above (minimum platforms needed given arrival and departure times)?
- Binary search with mid = (lo + hi) // 2 on the sorted array 2 5 8 12 16 23 38 56 72 91 110 130 looks for the key 91. How many probes…
- Standard binary search (lo = 0, hi = n−1, mid = (lo+hi)//2) runs on 3 7 11 15 19 23 27 31 35 to look for the absent key 20. How many…
- Insertion sort (ascending) is run on 6 3 8 1 5. Each time the inner loop compares the key with an element to its left, that is one…
- A top-down merge sort splits a range of size n into floor(n/2) and ceiling(n/2) parts and stops at size 1 or 0. Counting the root call…