Data Structures & AlgorithmsModerateWipro · Capgemini pattern
The array [1, 2, 3, 4, 5, 6] is first rotated RIGHT by 2 positions and then rotated LEFT by 5 positions. What is the result?
- A. [4, 5, 6, 1, 2, 3]
- B. [3, 4, 5, 6, 1, 2]
- C. [6, 1, 2, 3, 4, 5]
- D. [5, 6, 1, 2, 3, 4]
Correct answer: A. [4, 5, 6, 1, 2, 3]
Rotations compose by adding offsets: right 2 then left 5 = left 3 (mod 6). Left 3 of [1..6] is [4, 5, 6, 1, 2, 3]. Step by step: right 2 → [5, 6, 1, 2, 3, 4]; left 5 → [4, 5, 6, 1, 2, 3].
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 longest common prefix of the strings interview, internet, interval and intern?
- The first k = 4 elements of the queue 1, 2, 3, 4, 5, 6 (front first) are reversed using a stack: dequeue 4 items onto the stack, pop them…
- k sorted lists contain N elements in total. They are merged into one sorted list by repeatedly taking the smallest head from a min-heap…
- A deque of indices gives the MINIMUM of every window of size 3 in [4, 2, 12, 3, 8, 1, 7]. What are the window minima?
- A hash table of size 10 uses linear probing. Slots 2, 3, 4, 7 and 8 are occupied and all others are empty (no deletions have happened). An…
- Quickselect with Lomuto partition (pivot = last element) looks for the 3rd smallest element of [7, 2, 9, 4, 3, 8], recursing only into the…