Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The array [1, 2, 3, 4, 5, 6, 7] is rotated right by 3 positions (the last 3 elements move to the front). What is the element at index 0 after the rotation?
- A. 6
- B. 4
- C. 7
- D. 5
Correct answer: D. 5
A right rotation by k moves the last k elements to the front, so index 0 takes the element at index n−k. Rotating left by k gives a different first element.
More Coding Interview Problems questions
- Problem: Merging two sorted lists [1, 4, 7] and [2, 3, 8, 9] with the standard two-pointer merge, how many element comparisons are made in…
- Problem: In the expression print(232, (23)2) what are the two values printed, in order?
- Problem: What does this print? x = [1, 2, 3] y = x y += [4] z = x[:] z.append(5) print(len(x), len(z))
- Problem: What is printed by this snippet? d = {} d['b'] = 1 d['a'] = 2 d['b'] = 3 print(list(d.items()))
- Problem: What is the output? print(sorted({3,1,2} & {2,3,4}), 3 in {1,2,3}, len({1,1,2}))
- Problem: The number 1000000007 is used as a modulus in competitive programming. How many times does the decimal digit 7 appear in the…