Data Structures & AlgorithmsHardTCS NQT · Infosys pattern

The reversal algorithm rotates an array LEFT by k: reverse the first k elements, reverse the rest, then reverse the whole array. What is [1, 2, 3, 4, 5, 6, 7] after this with k = 3?

  1. A. 3 2 1 7 6 5 4
  2. B. 7 6 5 4 3 2 1
  3. C. 4 5 6 7 1 2 3
  4. D. 5 6 7 1 2 3 4

Correct answer: C. 4 5 6 7 1 2 3

Step 1: 3 2 1 4 5 6 7; step 2: 3 2 1 7 6 5 4; step 3: 4 5 6 7 1 2 3, a left rotation by 3. 5 6 7 1 2 3 4 is a right rotation by 3 (left by 4).

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic